Getting Started

Prerequisites

Goblin requires python version 3.5 to 3.8 and runs on gremlin-python drivers 3.2.4 and later.

Goblin is in the Pypi repository and as such can be installed through pip.

pip install goblin

The Basics

OGM

Define custom vertex/edge classes using the provided base goblin.element, goblin.properties.Property, and goblin.properties.

from goblin import element, properties
class Person(element.Vertex):
name = properties.Property(properties.String)
age = properties.Property(properties.Integer)
class Knows(element.Edge):
notes = properties.Property(properties.String, default='N/A')

Create a goblin.app.Goblin and register the element classes.

import asyncio
from goblin import Goblin
loop = asyncio.get_event_loop()
app = loop.run_until_complete(
Goblin.open(loop))
app.register(Person, Knows)

Other than user defined properties, elements provide no interface. Use a goblin.session.Session object to interact with the database.

async def go(app):
session = await app.session()
leif = Person()
leif.name = 'Leif'
leif.age = 28
jon = Person()
jon.name = 'Jonathan'
works_with = Knows(leif, jon)
session.add(leif, jon, works_with)
await session.flush()
result = await session.g.E(works_with.id).next()
assert result is works_with
people = session.traversal(Person) # element class based traversal source
async for person in people:
print(person)
loop.run_until_complete(go(app))

Note that a goblin.session does not necessarily correspond to a Gremlin Server session. Instead, all elements created using a session are 'live' in the sense that if the results of a traversal executed against the session result in different property values for an element, that element will be updated to reflect these changes.

Gremlin Language Variant

Generate and submit Gremlin traversals in native Python.

from goblin import DriverRemoteConnection # alias for aiogremlin.DriverRemoteConnection
from goblin import Graph # alias for aiogremlin.Graph
async def go(loop):
remote_connection = await DriverRemoteConnection.open(
'http://localhost:8182/gremlin', 'g')
g = Graph().traversal().withRemote(remote_connection)
vertices = await g.V().toList()
await remote_connection.close()
return vertices
results = loop.run_until_complete(go(loop))
# results = [v[...], ...]

Driver

Submit scripts and bindings.

import asyncio
from goblin import Cluster # alias for aiogremlin.Cluster
loop = asyncio.get_event_loop()
async def go(loop):
cluster = await Cluster.open(loop)
client = await cluster.connect()
resp = await client.submit(
"g.addV('developer').property(k1, v1)",
bindings={'k1': 'name', 'v1': 'Leif'})
async for msg in resp:
print(msg)
await cluster.close()
loop.run_until_complete(go(loop))