Neo4j Server: Client

Bulbs low-level client for Neo4j Server.

Constants

bulbs.neo4jserver.client.NEO4J_URI

The server’s default root URI ().

Neo4jClient

class bulbs.neo4jserver.client.Neo4jClient(config=None)[source]

Low-level client that sends a request to Neo4j Server and returns a response.

Parameters:

config (bulbs.config.Config) – Optional Config object. Defaults to default Config.

Variables:
  • config – Config object.
  • registry – Registry object.
  • scripts – GroovyScripts object.
  • type_system – JSONTypeSystem object.
  • request – Neo4jRequest object.

Example:

>>> from bulbs.neo4jserver import Neo4jClient
>>> client = Neo4jClient()
>>> response = client.get_all_vertices()
>>> result = response.results.next()
default_uri = 'http://localhost:7474/db/data/'

Default URI for the database.

request_class

Request class for the Client.

alias of Neo4jRequest

gremlin(script, params=None)[source]

Executes a Gremlin script and returns the Response.

Parameters:
  • script (str) – Gremlin script to execute.
  • params (dict) – Param bindings for the script.
Return type:

Neo4jResponse

cypher(query, params=None)[source]

Executes a Cypher query and returns the Response.

Parameters:
  • query (str) – Cypher query to execute.
  • params (dict) – Param bindings for the query.
Return type:

Neo4jResponse

create_vertex(data)[source]

Creates a vertex and returns the Response.

Parameters:data (dict) – Property data.
Return type:Neo4jResponse
get_vertex(_id)[source]

Gets the vertex with the _id and returns the Response.

Parameters:data (int) – Vertex ID.
Return type:Neo4jResponse
get_all_vertices()[source]

Returns a Response containing all the vertices in the Graph.

Return type:Neo4jResponse
update_vertex(_id, data)[source]

Updates the vertex with the _id and returns the Response.

Parameters:
  • _id (dict) – Vertex ID.
  • data (dict) – Property data.
Return type:

Neo4jResponse

delete_vertex(_id)[source]

Deletes a vertex with the _id and returns the Response.

Parameters:_id (dict) – Vertex ID.
Return type:Neo4jResponse
create_edge(outV, label, inV, data=None)[source]

Creates a edge and returns the Response.

Parameters:
  • outV (int) – Outgoing vertex ID.
  • label (str) – Edge label.
  • inV (int) – Incoming vertex ID.
  • data (dict or None) – Property data.
Return type:

Neo4jResponse

get_edge(_id)[source]

Gets the edge with the _id and returns the Response.

Parameters:data (int) – Edge ID.
Return type:Neo4jResponse
get_all_edges()[source]

Returns a Response containing all the edges in the Graph.

Return type:Neo4jResponse
update_edge(_id, data)[source]

Updates the edge with the _id and returns the Response.

Parameters:
  • _id (dict) – Edge ID.
  • data (dict) – Property data.
Return type:

Neo4jResponse

delete_edge(_id)[source]

Deletes a edge with the _id and returns the Response.

Parameters:_id (dict) – Edge ID.
Return type:Neo4jResponse
outE(_id, label=None, start=None, limit=None)[source]

Returns the outgoing edges of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

inE(_id, label=None, start=None, limit=None)[source]

Returns the incoming edges of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

bothE(_id, label=None, start=None, limit=None)[source]

Returns the incoming and outgoing edges of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

outV(_id, label=None, start=None, limit=None)[source]

Returns the out-adjacent vertices of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

inV(_id, label=None, start=None, limit=None)[source]

Returns the in-adjacent vertices of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

bothV(_id, label=None, start=None, limit=None)[source]

Returns the incoming- and outgoing-adjacent vertices of the vertex.

Parameters:
  • _id (dict) – Vertex ID.
  • label (str) – Optional edge label. Defaults to None.
Return type:

Neo4jResponse

create_vertex_index(index_name, *args, **kwds)[source]

Creates a vertex index with the specified params.

Parameters:index_name (str) – Name of the index to create.
Return type:Neo4jResponse
get_vertex_indices()[source]

Returns all the vertex indices.

Return type:Neo4jResponse
get_vertex_index(index_name)[source]

Returns the vertex index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:Neo4jResponse
get_or_create_vertex_index(index_name, *args, **kwds)[source]

Get a Vertex Index or create it if it doesn’t exist.

Parameters:
  • index_name (str) – Index name.
  • index_config (dict) – Index configuration.
Return type:

bulbs.neo4jserver.index.Index

delete_vertex_index(index_name)[source]

Deletes the vertex index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:Neo4jResponse
create_edge_index(index_name, *args, **kwds)[source]

Creates a edge index with the specified params.

Parameters:index_name (str) – Name of the index.
Return type:Neo4jResponse
get_edge_indices()[source]

Returns a dict of all the vertex indices.

Return type:Neo4jResponse
get_edge_index(index_name)[source]

Returns the edge index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:Neo4jResponse
get_or_create_edge_index(index_name, *args, **kwds)[source]

Get a Edge Index or create it if it doesn’t exist.

Parameters:
  • index_name (str) – Index name.
  • index_config (dict) – Index configuration.
Return type:

bulbs.neo4jserver.index.Index

delete_edge_index(index_name)[source]

Deletes the edge index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:Neo4jResponse
put_vertex(index_name, key, value, _id)[source]

Adds a vertex to the index with the index_name.

Parameters:
  • index_name (str) – Name of the index.
  • key (str) – Name of the key.
  • value (str) – Value of the key.
  • _id (int) – Vertex ID
Return type:

Neo4jResponse

lookup_vertex(index_name, key, value)[source]

Returns the vertices indexed with the key and value.

Parameters:
  • index_name (str) – Name of the index.
  • key (str) – Name of the key.
  • value (str) – Value of the key.
Return type:

Neo4jResponse

query_vertex(index_name, query)[source]

Queries the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • query (str) – Lucene query string
Return type:

Neo4jResponse

remove_vertex(index_name, _id, key=None, value=None)[source]

Removes a vertex from the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • key (str) – Optional. Name of the key.
  • value (str) – Optional. Value of the key.
Return type:

Neo4jResponse

put_edge(index_name, key, value, _id)[source]

Adds an edge to the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • key (str) – Name of the key.
  • value (str) – Value of the key.
  • _id (int) – Edge ID
Return type:

Neo4jResponse

lookup_edge(index_name, key, value)[source]

Looks up an edge in the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • key (str) – Name of the key.
  • value (str) – Value of the key.
Return type:

Neo4jResponse

query_edge(index_name, query)[source]

Queries the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • query (str) – Lucene query string
Return type:

Neo4jResponse

remove_edge(index_name, _id, key=None, value=None)[source]

Removes an edge from the index and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • _id (int) – Edge ID
  • key (str) – Optional. Name of the key.
  • value (str) – Optional. Value of the key.
Return type:

Neo4jResponse

create_indexed_vertex(data, index_name, keys=None)[source]

Creates a vertex, indexes it, and returns the Response.

Parameters:
  • data (dict) – Property data.
  • index_name (str) – Name of the index.
  • keys (list) – Property keys to index.
Return type:

Neo4jResponse

update_indexed_vertex(_id, data, index_name, keys=None)[source]

Updates an indexed vertex and returns the Response.

Parameters:
  • index_name (str) – Name of the index.
  • data (dict) – Property data.
  • index_name – Name of the index.
  • keys (list) – Property keys to index.
Return type:

Neo4jResponse

create_indexed_edge(outV, label, inV, data, index_name, keys=None)[source]

Creates a edge, indexes it, and returns the Response.

Parameters:
  • outV (int) – Outgoing vertex ID.
  • label (str) – Edge label.
  • inV (int) – Incoming vertex ID.
  • data (dict) – Property data.
  • index_name (str) – Name of the index.
  • keys (list) – Property keys to index. Defaults to None (indexes all properties).
Return type:

Neo4jResponse

update_indexed_edge(_id, data, index_name, keys=None)[source]

Updates an indexed edge and returns the Response.

Parameters:
  • _id (int) – Edge ID.
  • data (dict) – Property data.
  • index_name (str) – Name of the index.
  • keys (list) – Property keys to index. Defaults to None (indexes all properties).
Return type:

Neo4jResponse

set_metadata(key, value)[source]

Sets the metadata key to the supplied value.

Parameters:
  • key (str) – Metadata key
  • value (str, int, or list) – Metadata value.
Return type:

Neo4jResponse

get_metadata(key, default_value=None)[source]

Returns the value of metadata for the key.

Parameters:
  • key (str) – Metadata key
  • default_value (str, int, or list) – Default value to return if the key is not found.
Return type:

Neo4jResponse

remove_metadata(key)[source]

Removes the metadata key and value.

Parameters:key (str) – Metadata key
Return type:Neo4jResponse

Neo4jRequest

class bulbs.neo4jserver.client.Neo4jRequest(config, content_type)[source]

Makes HTTP requests to Neo4j Server and returns a Neo4jResponse.

response_class

alias of Neo4jResponse

get(path, params=None)

Convenience method that sends GET requests to the client.

Parameters:
  • path (str) – Path to the server resource, relative to the root URI.
  • params (dict) – Optional URI params for the resource.
Return type:

Response

put(path, params=None)

Convenience method that sends PUT requests to the client.

Parameters:
  • path (str) – Path to the server resource, relative to the root URI.
  • params (dict) – Optional URI params for the resource.
Return type:

Response

post(path, params=None)

Convenience method that sends POST requests to the client.

Parameters:
  • path (str) – Path to the server resource, relative to the root URI.
  • params (dict) – Optional URI params for the resource.
Return type:

Response

delete(path, params=None)

Convenience method that sends DELETE requests to the client.

Parameters:
  • path (str) – Path to the server resource, relative to the root URI.
  • params (dict) – Optional URI params for the resource.
Return type:

Response

send(message)

Convenience method that sends request messages to the client.

Parameters:
  • message – Tuple containing: (HTTP method, path, params)
  • params (dict) – Optional URI params for the resource.
Return type:

Response

request(method, path, params)

Sends a request to the client.

Parameters:
  • method (str) – HTTP method: GET, PUT, POST, or DELETE.
  • path (str) – Path to the server resource, relative to the root URI.
  • params (dict) – Optional URI parameters for the resource.
Return type:

Response

Neo4jResponse

class bulbs.neo4jserver.client.Neo4jResponse(response, config)[source]

Container class for the server response.

Parameters:
  • response (tuple) – httplib2 response: (headers, content).
  • config (bulbs.config.Config) – Config object.
Variables:
  • config – Config object.
  • headers – httplib2 response headers, see:
  • content – A dict containing the HTTP response content.
  • results – A generator of Neo4jResult objects, a single Neo4jResult object, or None, depending on the number of results returned.
  • total_size – The number of results returned.
  • raw – Raw HTTP response. Only set when log_level is DEBUG.
result_class

alias of Neo4jResult

handle_response(response)[source]

Check the server response and raise exception if needed.

Parameters:response (tuple) – httplib2 response: (headers, content).
Return type:None
get_headers(response)[source]

Returns a dict containing the headers from the response.

Parameters:response (tuple) – httplib2 response: (headers, content).
Return type:httplib2.Response
get_content(response)[source]

Returns a dict containing the content from the response.

Parameters:response (tuple) – httplib2 response: (headers, content).
Return type:dict or None
get_results()[source]

Returns the results contained in the response.

Returns:A tuple containing two items: 1. Either a generator of Neo4jResult objects, a single Neo4jResult object, or None, depending on the number of results returned; 2. An int representing the number results returned.
Return type:tuple
get(attribute)

Return a client-specific attribute.

one()

Returns one result or raises an error if there is more than one result.

Return type:Result

Neo4jResult

class bulbs.neo4jserver.client.Neo4jResult(result, config)[source]

Container class for a single result, not a list of results.

Parameters:
  • result (dict) – The raw result.
  • config (Config) – The graph Config object.
Variables:
  • raw – The raw result.
  • data – The data in the result.
get_id()[source]

Returns the element ID.

Return type:int
get_type()[source]

Returns the element’s base type, either “vertex” or “edge”.

Return type:str
get_data()[source]

Returns the element’s property map.

Return type:dict
get_uri()[source]

Returns the element URI.

Return type:str
get_outV()[source]

Returns the ID of the edge’s outgoing vertex (start node).

Return type:int
get_inV()[source]

Returns the ID of the edge’s incoming vertex (end node).

Return type:int
get_label()[source]

Returns the edge label (relationship type).

Return type:str
get_index_name()[source]

Returns the index name.

Return type:str
get_index_class()[source]

Returns the index class, either “vertex” or “edge”.

Return type:str
get(attribute)[source]

Returns the value of a client-specific attribute.

Parameters:attribute (str) – Name of the attribute.
Return type:str