Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a section showing how to talk to a Gremlin Server from the Python console #138

Open
krlawrence opened this issue Feb 24, 2019 · 1 comment

Comments

@krlawrence
Copy link
Owner

It is fairly straightforward to bootstrap an environment inside the Python console so that it can be used with a Gremlin Server. This has the advantage of being able to mix Gremlin and Python (and also use Python variables to manipulate results).

# Configure the environment so the Python Console can connect to
# a Gremlin Server using gremlin-python and a web socket connection.
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.traversal import 
import os
server = os.environ["GREMLIN_SERVER_NAME"]
port = os.environ["GREMLIN_SERVER_PORT"]

endpoint = 'ws://' + server + ':' + port + '/gremlin'
print(endpoint)

graph=Graph()
connection = DriverRemoteConnection(endpoint,'g')
g = graph.traversal().withRemote(connection)
@fridex
Copy link
Contributor

fridex commented Feb 25, 2019

Let me know if I can be somehow helpful here.

We are using JanusGraph with Python to analyze Python packages in the Python ecosystem. Here is an example notebook published (the repo it lives in has more notebooks) and here is our graph database adapter for using Gramlin queries and connecting to JanusGraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants