Neo4j Server: Gremlin

Bulbs API for executing Gremlin scripts on Neo4j Server.

Gremlin comes in several variations:

  • Gremlin-Groovy (the original)
  • Gremlin-Java
  • Gremlin-Scala

Gremlin-JavaScript is in the works, and Gremlin-Jython is on deck to be completed after Gremlin-JavaScript.

Neo4j Server supports the original Gremlin-Groovy, and the new JavaScript plugin (https://github.com/neo4j/javascript-plugin) is ready for when Gremlin-JavaScript is released.

Gremlin-Groovy

Use the standard Bulbs Gremlin interface to execute Gremlin-Groovy scrips on Neo4j Server.

Example:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> script = g.scripts.get('get_movie_recommendations')
>>> params = dict(user_id=3)
>>> vertices = g.gremlin.query(script, params)
>>> vertex = vertices.next()

Here, “get_movie_recommendations” is a Gremln-Groovy script in your local Groovy library.

Loading Custom Functions

You can add a custom Groovy file to the scripts index like this:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> file_path = "/home/james/code/myGremlinScripts.groovy"
>>> g.scripts.update(file_path)

Bulbs will parse the Groovy file and store each function in a dict, with its function name as the key. If one of the newly-loaded functions has the same name as an existing function, it will override the existing function with your custom script.

Refreshing Scripts

If you make changes to the Groovy file while the object is loaded, you can refresh the loaded scripts like this:

>>> g.scripts.refresh()