Using the Driver

Connecting to a Cluster

To take advantage of the higher level features of the driver, Goblin provides the Cluster object. Cluster is used to create multi-host clients that leverage connection pooling and sharing. Its interface is based on the TinkerPop Java driver:

>>> async def print_results(gremlin='1+1'):
...     # opens a cluster with default config
...     cluster = await'')
...     client = await cluster.connect()
...     # round robin requests to available hosts
...     resp = await client.submit(gremlin=gremlin)
...     async for msg in resp:
...         print(msg)
...     await cluster.close()  # Close all connections to all hosts

And that is it. While Cluster is simple to learn and use, it provides a wide variety of configuration options.

Configuring Cluster

Configuration options can be set on Cluster in one of two ways, either passed as keyword arguments to open, or stored in a configuration file and passed to the open using the kwarg configfile. Configuration files can be either YAML or JSON format. Currently, Cluster uses the following configuration:

Key Description Default
scheme URI scheme, typically ‘ws’ or ‘wss’ for secure websockets ‘ws’
hosts A list of hosts the cluster will connect to [‘localhost’]
port The port of the Gremlin Server to connect to, same for all hosts 8182
ssl_certfile File containing ssl certificate ‘’
ssl_keyfile File containing ssl key ‘’
ssl_password File containing password for ssl keyfile ‘’
username Username for Gremlin Server authentication ‘’
password Password for Gremlin Server authentication ‘’
response_timeout Timeout for reading responses from the stream None
max_conns The maximum number of connections open at any time to this host 4
min_conns The minimum number of connection open at any time to this host 1
max_times_acquired The maximum number of times a single pool connection can be acquired and shared 16
max_inflight The maximum number of unresolved messages that may be pending on any one connection 64
message_serializer String denoting the class used for message serialization, currently only supports basic GraphSONMessageSerializer ‘classpath’

For information related to improving driver performance, please refer to the performance section.