No description, website, or topics provided.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 673 commits behind maxdemarzi:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Welcome to Neography

Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:

If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at


gem install 'neography'

After that, in your ruby script, do

require 'rubygems'
require 'neography'

in order to access the functionality.


for use:

for development:


Just add gem 'neography' to your Gemfile and run bundle install


A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil:

#                            protocol,  server,        port,  log_file,           log_enabled
@neo = ('http://', '', 7479, 'log/neography.log', true)

Default Parameters are:

@neo = ('http://', 'localhost', 7474, '/neography.log', false)

To Use:

@neo = 

@neo.get_root                                              # Get the root node
node1 = @neo.create_node                                   # Create an empty node
node2 = @neo.create_node("age" => 31, "name" => "Max")     # Create a node with some properties
@neo.get_node(node2)                                       # Get a node and its properties
@neo.delete_node(node2)                                    # Delete an unrelated node
@neo.delete_node!(node2)                                   # Delete a node and all its relationships

@neo.reset_node_properties(node1, {"age" => 31})           # Reset a node's properties
@neo.set_node_properties(node1, {"weight" => 200})         # Set a node's properties
@neo.get_node_properties(node1)                            # Get just the node properties
@neo.get_node_properties(node1, ["weight","age"])          # Get some of the node properties
@neo.remove_node_properties(node1)                         # Remove all properties of a node
@neo.remove_node_properties(node1, "weight")               # Remove one property of a node
@neo.remove_node_properties(node1, ["weight","age"])       # Remove multiple properties of a node

rel1 = @neo.create_relationship("friends", node1, node2)   # Create a relationship between node1 and node2
rel2 = @neo.get_relationship(rel1)                         # Get a relationship
@neo.get_node_relationships(node1)                         # Get all relationships
@neo.get_node_relationships(node1, "in")                   # Get only incoming relationships
@neo.get_node_relationships(node1, "all", "enemies")       # Get all relationships of type enemies
@neo.get_node_relationships(node1, "in", "enemies")        # Get only incoming relationships of type enemies
@neo.delete_relationship(rel1)                             # Delete a relationship

@neo.reset_relationship_properties(rel1, {"age" => 31})    # Reset a relationship's properties
@neo.set_relationship_properties(rel1, {"weight" => 200})  # Set a relationship's properties
@neo.get_relationship_properties(rel1)                     # Get just the relationship properties
@neo.get_relationship_properties(rel1, ["since","met"])    # Get some of the relationship properties
@neo.remove_relationship_properties(rel1)                  # Remove all properties of a relationship
@neo.remove_relationship_properties(rel1, "since")         # Remove one property of a relationship
@neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship

@neo.list_indexes                                          # doesn't really seam to do what the api says it does
@neo.add_to_index(key, value, node1)                       # adds a node to an index with the given key/value pair
@neo.remove_from_index(key, value, node1)                  # removes a node to an index with the given key/value pair
@neo.get_index(key, value)                                 # gets an index with the given key/value pair

@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes 
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths")    # finds all paths between two nodes

nodes = @neo.traverse(node1,                                              # the node where the traversal starts
                      "nodes",                                            # return_type "nodes", "relationships" or "paths"
                      {"order" => "breadth first",                        # "breadth first" or "depth first" traversal order
                       "uniqueness" => "node global",                     # See Uniqueness in API documentation for options.
                       "relationships" => [{"type"=> "roommates",         # A hash containg a description of the traversal
                                            "direction" => "all"},        # two relationships. 
                                           {"type"=> "friends",           # 
                                            "direction" => "out"}],       # 
                       "prune evaluator" => {"language" => "javascript",  # A prune evaluator (when to stop traversing)
                                             "body" => "position.endNode().getProperty('age') < 21;"},
                       "return filter" => {"language" => "builtin",       # "all" or "all but start node"
                                           "name" => "all"},
                       "depth" => 4})  

# "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth. 
# If not specified a depth of 1 is used and if a "prune evaluator" is specified instead of a depth, no depth limit is set.

Please see the specs for more examples.


nodes = @neo.create_nodes(5)                                              # Create 5 empty nodes
nodes = @neo.create_nodes_threaded(5)                                     # Create 5 empty nodes using threads
nodes = @neo.create_node_nodes([{"age" => 31, "name" => "Max"},
                                {"age" => 24, "name" => "Alex"})          # Create two nodes with properties
nodes = @neo.create_node_nodes_threaded([{"age" => 31, "name" => "Max"},
                                         {"age" => 24, "name" => "Alex"}) # Create two nodes with properties threaded
nodes = @neo.get_nodes([17,86,397,33])                                    # Get four nodes by their id

one_set_nodes = @neo.create_nodes(3) 
another_node = @neo.create_node("age" => 31, "name" => "Max")
nodes = @neo.get_nodes([one_set_nodes, another_node])                     # Get four nodes

See Neo4j API for:


A couple of examples borrowed from Matthew Deiters's Neo4jr-social

To Do

  • More tests

  • More examples

  • batch import with typhoeus ?

  • create proper objects for Node and Relationship