Skip to main content

Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP). Gremlin is the graph traversal language of TinkerPop. It can be described as a functional, data-flow language that enables users to succinctly express complex traversals on (or queries of) their application’s property graph.

Gremlin-Python implements Gremlin within the Python language and can be used on any Python virtual machine including the popular CPython machine. Python’s syntax has the same constructs as Java including “dot notation” for function chaining (a.b.c), round bracket function arguments (a(b,c)), and support for global namespaces (a(b()) vs a(__.b())). As such, anyone familiar with Gremlin-Java will immediately be able to work with Gremlin-Python. Moreover, there are a few added constructs to Gremlin-Python that make traversals a bit more succinct.

Gremlin-Python is designed to connect to a “server” that is hosting a TinkerPop-enabled graph system. That “server” could be Gremlin Server or a remote Gremlin provider that exposes protocols by which Gremlin-Python can connect.

A typical connection to a server running on “localhost” that supports the Gremlin Server protocol using websockets from the Python shell looks like this:

>>> from gremlin_python.process.anonymous_traversal import traversal
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
>>> g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))

Once “g” has been created using a connection, it is then possible to start writing Gremlin traversals to query the remote graph:

>>> g.V().both()[1:3].toList()
[v[2], v[4]]
>>> g.V().both()[1].toList()
[v[2]]
>>> g.V().both().name.toList()
[lop, vadas, josh, marko, marko, josh, peter, ripple, lop, marko, josh, lop]

Sample Traversals

The Gremlin language allows users to write highly expressive graph traversals and has a broad list of functions that cover a wide body of features. The Reference Documentation describes these functions and other aspects of the TinkerPop ecosystem including some specifics on Gremlin in Python itself. Most of the examples found in the documentation use Groovy language syntax in the Gremlin Console. For the most part, these examples should generally translate to Python with some modification. Given the strong correspondence between canonical Gremlin in Java and its variants like Python, there is a limited amount of Python-specific documentation and examples. This strong correspondence among variants ensures that the general Gremlin reference documentation is applicable to all variants and that users moving between development languages can easily adopt the Gremlin variant for that language.

Create Vertex

from gremlin_python.process.traversal import T
from gremlin_python.process.traversal import Cardinality

id = T.id
single = Cardinality.single

def create_vertex(self, vid, vlabel):
    # default database cardinality is used when Cardinality argument is not specified
    g.addV(vlabel).property(id, vid). \
      property(single, 'name', 'Apache'). \
      property('lastname', 'Tinkerpop'). \
      next()

Find Vertices

def list_all(self, limit=500):
    g.V().limit(limit).elementMap().toList()

def find_vertex(self, vid):
    g.V(vid).elementMap().next()

def list_by_label_name(self, vlabel, name):
    g.V().has(vlabel, 'name', name).elementMap().toList()

Update Vertex

from gremlin_python.process.traversal import Cardinality

single = Cardinality.single

def update_vertex(self, vid, name):
    g.V(vid).property(single, 'name', name).next()

NOTE that versions suffixed with “rc” are considered release candidates (i.e. pre-alpha, alpha, beta, etc.) and thus for early testing purposes only.

Release files for gremlinpython 3.5.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gremlinpython 3.5.8
File Size Uploaded
gremlinpython-3.5.8.tar.gz 46.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gremlinpython 3.5.8
File Interpreter ABI Platform
gremlinpython-3.5.8-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 119.0 kB

Release files / gremlinpython-3.5.8.tar.gz

Download URL gremlinpython-3.5.8.tar.gz
Size 46.6 kB
Tags Source
SHA-256 checksum
How to use checksums
de12d0c3f5ae973097ad4b46e972bd261eec8df5d3bb7f7dc8156d4afe61ff22
BLAKE2b-256 checksum
How to use checksums
1c7e33156b0119723d6b75c6e051f06b7584e150bbaeca4afdc5574ae12784c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / gremlinpython-3.5.8-py2.py3-none-any.whl

Download URL gremlinpython-3.5.8-py2.py3-none-any.whl
Size 72.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
61d8bb18be8e2b675ac312451500deaa04c0f19936fd48451c0d9cce78207235
BLAKE2b-256 checksum
How to use checksums
9a0460021d48548c01d7868cc392bd7e5a915726a7152a9ae6247cdcd867a843
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

3.8.2

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.7

2 release files

3.7.6

2 release files

3.7.5

2 release files

3.7.4

2 release files

3.7.3

2 release files

3.7.2

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.8

2 release files

3.6.7

2 release files

3.6.6

2 release files

3.6.5

2 release files

3.6.4

2 release files

3.6.3

2 release files

3.6.2

2 release files

3.6.1

2 release files

3.6.0

2 release files

This release

3.5.8 This release

2 release files

3.5.7

2 release files

3.5.6

2 release files

3.5.5

2 release files

3.5.4

2 release files

3.5.3

2 release files

3.5.2

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.13

2 release files

3.4.12

2 release files

3.4.11

2 release files

3.4.10

2 release files

3.4.9

2 release files

3.4.8

2 release files

3.4.7

2 release files

3.4.6

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.3

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.9

2 release files

3.3.8

2 release files

3.3.7

2 release files

3.3.6

2 release files

3.3.5

2 release files

3.3.4

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.10

2 release files

3.2.9

2 release files

3.2.8

2 release files

3.2.7

2 release files

3.2.6

2 release files

3.2.5

2 release files

3.2.4

2 release files

3.2.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page