aiogremlin.driver package

Submodules

aiogremlin.driver.client module

Client for the Tinkerpop 3 Gremlin Server.

class aiogremlin.driver.client.Client(cluster, loop, *, hostname=None, aliases=None)[source]

Bases: object

Client that utilizes a Cluster to access a cluster of Gremlin Server hosts. Issues requests to hosts using a round robin strategy.

Parameters
alias(aliases)[source]
property aliases

Read-only property

async close()[source]
property cluster

Read-only property.

Returns

The instance of Cluster associated with client.

property message_serializer

Read-only property

async submit(message, bindings=None)[source]

coroutine Submit a script and bindings to the Gremlin Server.

Parameters
  • message – Can be an instance of RequestMessage<gremlin_python.driver.request.RequestMessage> or Bytecode<gremlin_python.process.traversal.Bytecode> or a str representing a raw Gremlin script

  • bindings (dict) – Optional bindings used with raw Grelmin

Returns

ResultSet object

aiogremlin.driver.cluster module

class aiogremlin.driver.cluster.Cluster(loop, aliases=None, **config)[source]

Bases: object

A cluster of Gremlin Server hosts. This object provides the main high level interface used by the aiogremlin module.

Parameters
  • loop (asyncio.BaseEventLoop) –

  • aliases (dict) – Optional mapping for aliases. Default is None

  • config – Optional cluster configuration passed as kwargs or dict

DEFAULT_CONFIG = {'hosts': ['localhost'], 'max_conns': 4, 'max_inflight': 64, 'max_times_acquired': 16, 'message_serializer': 'gremlin_python.driver.serializer.GraphSONMessageSerializer', 'min_conns': 1, 'password': '', 'port': 8182, 'provider': 'aiogremlin.driver.provider.TinkerGraph', 'response_timeout': None, 'scheme': 'ws', 'ssl_certfile': '', 'ssl_keyfile': '', 'ssl_password': '', 'username': ''}
async close()[source]

coroutine Close cluster and all connected hosts.

property config

Read-only property.

Returns

dict containing the cluster configuration

config_from_file(filename)[source]

Load configuration from from file.

Parameters

filename (str) – Path to the configuration file.

config_from_json(filename)[source]

Load configuration from from JSON file.

Parameters

filename (str) – Path to the configuration file.

config_from_module(module)[source]

Load configuration from Python module.

Parameters

filename (str) – Path to the configuration file.

config_from_yaml(filename)[source]

Load configuration from from YAML file.

Parameters

filename (str) – Path to the configuration file.

async connect(hostname=None, aliases=None)[source]

coroutine Get a connected client. Main API method.

Returns

A connected instance of Client<aiogremlin.driver.client.Client>

async establish_hosts()[source]

coroutine Connect to all hosts as specified in configuration.

async get_connection(hostname=None)[source]

coroutine Get connection from next available host in a round robin fashion.

Returns

Connection

property hosts

Read-only property

classmethod open(loop, *, aliases=None, configfile=None, **config)[source]

coroutine Open a cluster, connecting to all available hosts as specified in configuration.

Parameters
  • loop (asyncio.BaseEventLoop) –

  • aliases (dict) – Optional mapping for aliases. Default is None

  • configfile (str) – Optional configuration file in .json or .yml format

  • config – Optional cluster configuration passed as kwargs or dict

aiogremlin.driver.cluster.my_import(name)[source]

aiogremlin.driver.connection module

class gremlin_python.driver.protocol.AbstractBaseProtocol[source]
class aiogremlin.driver.connection.Connection(url, transport, protocol, loop, username, password, max_inflight, response_timeout, message_serializer, provider)[source]

Bases: object

Main classd for interacting with the Gremlin Server. Encapsulates a websocket connection. Not instantiated directly. Instead use :py:meth::Connection.open<aiogremlin.driver.connection.Connection.open>.

Parameters
async close()[source]

coroutine Close underlying connection and mark as closed.

property closed

Read-only property. Check if connection has been closed.

Returns

bool

property message_serializer
classmethod open(url, loop, *, protocol=None, transport_factory=None, ssl_context=None, username='', password='', max_inflight=64, response_timeout=None, message_serializer=<class 'gremlin_python.driver.serializer.GraphSONMessageSerializer'>, provider=<class 'aiogremlin.driver.provider.TinkerGraph'>)[source]

coroutine Open a connection to the Gremlin Server.

Parameters
  • url (str) – url for host Gremlin Server

  • loop (asyncio.BaseEventLoop) –

  • protocol (gremlin_python.driver.protocol.AbstractBaseProtocol) – Protocol implementation

  • transport_factory – Factory function for transports

  • ssl_context (ssl.SSLContext) –

  • username (str) – Username for database auth

  • password (str) – Password for database auth

  • max_inflight (int) – Maximum number of unprocessed requests at any one time on the connection

  • response_timeout (float) – (optional) None by default

  • message_serializer – Message serializer implementation

  • provider – Graph provider object implementation

Returns

Connection

async submit(message)

Submit a script and bindings to the Gremlin Server

Parameters

message (RequestMessage<gremlin_python.driver.request.RequestMessage>) –

Returns

ResultSet object

property url

Readonly property.

Returns

str The url association with this connection.

async write(message)[source]

Submit a script and bindings to the Gremlin Server

Parameters

message (RequestMessage<gremlin_python.driver.request.RequestMessage>) –

Returns

ResultSet object

aiogremlin.driver.pool module

class aiogremlin.driver.pool.ConnectionPool(url, loop, ssl_context, username, password, max_conns, min_conns, max_times_acquired, max_inflight, response_timeout, message_serializer, provider)[source]

Bases: object

A pool of connections to a Gremlin Server host.

Parameters
  • url (str) – url for host Gremlin Server

  • loop (asyncio.BaseEventLoop) –

  • ssl_context (ssl.SSLContext) –

  • username (str) – Username for database auth

  • password (str) – Password for database auth

  • response_timeout (float) – (optional) None by default

  • max_conns (int) – Maximum number of conns to a host

  • min_connsd (int) – Minimum number of conns to a host

  • max_times_acquired (int) – Maximum number of times a conn can be shared by multiple coroutines (clients)

  • max_inflight (int) – Maximum number of unprocessed requests at any one time on the connection

async acquire()[source]

coroutine Acquire a new connection from the pool.

async close()[source]

coroutine Close connection pool.

async init_pool()[source]

coroutine Open minumum number of connections to host

release(conn)[source]

Release connection back to pool after use.

Parameters

conn (PooledConnection) –

property url

Readonly property.

Returns

str

class aiogremlin.driver.pool.PooledConnection(conn, pool)[source]

Bases: object

Wrapper for Connection that helps manage tomfoolery associated with connection pooling.

Parameters
async close()[source]

Close underlying connection

property closed

Readonly property.

Returns

bool

decrement_acquired()[source]

Decrement times acquired attribute by 1

increment_acquired()[source]

Increment times acquired attribute by 1

release()[source]
async release_task(resp)[source]
async submit(message)

coroutine Submit a script and bindings to the Gremlin Server

Parameters
  • processor (str) – Gremlin Server processor argument

  • op (str) – Gremlin Server op argument

  • args – Keyword arguments for Gremlin Server. Depend on processor and op.

Returns

aiohttp.ClientResponse object

property times_acquired

Readonly property.

Returns

int

async write(message)[source]

coroutine Submit a script and bindings to the Gremlin Server

Parameters
  • processor (str) – Gremlin Server processor argument

  • op (str) – Gremlin Server op argument

  • args – Keyword arguments for Gremlin Server. Depend on processor and op.

Returns

aiohttp.ClientResponse object

aiogremlin.driver.protocol module

class aiogremlin.driver.protocol.GremlinServerWSProtocol(message_serializer, username='', password='')[source]

Bases: gremlin_python.driver.protocol.AbstractBaseProtocol

Implemenation of the Gremlin Server Websocket protocol

connection_made(transport)[source]
async data_received(data, results_dict)[source]
async write(request_id, request_message)[source]
class aiogremlin.driver.protocol.Message(status_code, data, message)

Bases: tuple

data

Alias for field number 1

message

Alias for field number 2

status_code

Alias for field number 0

aiogremlin.driver.provider module

class aiogremlin.driver.provider.Provider[source]

Bases: object

Superclass for provider plugins

DEFAULT_OP_ARGS = {}
classmethod get_default_op_args(processor)[source]
class aiogremlin.driver.provider.TinkerGraph[source]

Bases: aiogremlin.driver.provider.Provider

Default provider

static get_hashable_id(val)[source]

aiogremlin.driver.resultset module

class aiogremlin.driver.resultset.ResultSet(request_id, timeout, loop)[source]

Bases: object

Gremlin Server response implementated as an async iterator.

property aggregate_to
async all()[source]
close()[source]
property done

Readonly property.

Returns

asyncio.Event object

async one()[source]

Get a single message from the response stream

queue_result(result)[source]
property request_id
property stream
aiogremlin.driver.resultset.error_handler(fn)[source]

aiogremlin.driver.server module

class aiogremlin.driver.server.GremlinServer(url, loop, **config)[source]

Bases: object

Class that wraps a connection pool. Currently doesn’t do much, but may be useful in the future….

Parameters

pool (pool.ConnectionPool) –

async close()[source]

coroutine Close underlying connection pool.

async get_connection()[source]

coroutine Acquire a connection from the pool.

async initialize()[source]
classmethod open(url, loop, **config)[source]

coroutine Establish connection pool and host to Gremlin Server.

Parameters
  • url (str) – url for host Gremlin Server

  • loop (asyncio.BaseEventLoop) –

  • ssl_context (ssl.SSLContext) –

  • username (str) – Username for database auth

  • password (str) – Password for database auth

  • response_timeout (float) – (optional) None by default

  • max_conns (int) – Maximum number of conns to a host

  • min_connsd (int) – Minimum number of conns to a host

  • max_times_acquired (int) – Maximum number of times a conn can be shared by multiple coroutines (clients)

  • max_inflight (int) – Maximum number of unprocessed requests at any one time on the connection

Returns

GremlinServer

property pool

Readonly property.

Returns

ConnectionPool

property url

Module contents