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]
aliases

Read-only property

close()[source]
cluster

Read-only property.

Returns:The instance of Cluster associated with client.
message_serializer

Read-only property

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

coroutine Close cluster and all connected hosts.

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.
connect(hostname=None, aliases=None)[source]

coroutine Get a connected client. Main API method.

Returns:A connected instance of Client<aiogremlin.driver.client.Client>
establish_hosts()[source]

coroutine Connect to all hosts as specified in configuration.

get_connection(hostname=None)[source]

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

Returns:Connection
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:
close()[source]

coroutine Close underlying connection and mark as closed.

closed

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

Returns:bool
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

submit(message)

Submit a script and bindings to the Gremlin Server

Parameters:message (RequestMessage<gremlin_python.driver.request.RequestMessage>) –
Returns:ResultSet object
url

Readonly property.

Returns:str The url association with this connection.
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
acquire()[source]

coroutine Acquire a new connection from the pool.

close()[source]

coroutine Close connection pool.

init_pool()[source]

coroutine Open minumum number of connections to host

release(conn)[source]

Release connection back to pool after use.

Parameters:conn (PooledConnection) –
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:
close()[source]

Close underlying connection

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]
release_task(resp)[source]
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

times_acquired

Readonly property.

Returns:int
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]
data_received(data, results_dict)[source]
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.

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

Readonly property.

Returns:asyncio.Event object
one()[source]

Get a single message from the response stream

queue_result(result)[source]
request_id
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) –
close()[source]

coroutine Close underlying connection pool.

get_connection()[source]

coroutine Acquire a connection from the pool.

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

pool

Readonly property.

Returns:ConnectionPool
url

Module contents