Rexster: Client

Bulbs low-level client for Rexster.

Constants

bulbs.rexster.client.REXSTER_URI

The server’s default root URI ().

RexsterClient

class bulbs.rexster.client.RexsterClient(config=None, db_name=None)[source]

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

Parameters:

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

Variables:
  • default_uri – Default URI for the database.
  • request_class – Request class for the Client.
  • config – Config object.
  • registry – Registry object.
  • scripts – GroovyScripts object.
  • type_system – JSONTypeSystem object.
  • request – RexsterRequest object.

Example:

>>> from bulbs.rexster import RexsterClient
>>> client = RexsterClient()
>>> script = client.scripts.get("get_vertices")
>>> response = client.gremlin(script, params=None)
>>> result = response.results.next()
default_uri = 'http://localhost:8182/graphs/emptygraph'

Default URI for the database.

request_class

alias of RexsterRequest

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:

RexsterResponse

create_vertex(data)[source]

Creates a vertex and returns the Response.

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

Gets the vertex with the _id and returns the Response.

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

Returns a Response containing all the vertices in the Graph.

Return type:RexsterResponse
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:

RexsterResponse

delete_vertex(_id)[source]

Deletes a vertex with the _id and returns the Response.

Parameters:_id (dict) – Vertex ID.
Return type:RexsterResponse
create_edge(outV, label, inV, data={})[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:

RexsterResponse

get_edge(_id)[source]

Gets the edge with the _id and returns the Response.

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

Returns a Response containing all the edges in the Graph.

Return type:RexsterResponse
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:

RexsterResponse

delete_edge(_id)[source]

Deletes a edge with the _id and returns the Response.

Parameters:_id (dict) – Edge ID.
Return type:RexsterResponse
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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

get_all_indices()[source]

Returns a list of all the element indices.

delete_index(name)[source]

Deletes the index with the index_name.

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:RexsterResponse
get_vertex_index(index_name)[source]

Returns the vertex index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:RexsterResponse
delete_vertex_index(name)[source]

Deletes the vertex index with the index_name.

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

Creates a edge index with the specified params.

Parameters:index_name (str) – Name of the index.
Return type:RexsterResponse
get_edge_index(name)[source]

Returns the edge index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:RexsterResponse
delete_edge_index(name)[source]

Deletes the edge index with the index_name.

Parameters:index_name (str) – Name of the index.
Return type:RexsterResponse
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:

RexsterResponse

lookup_vertex(index_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:

RexsterResponse

query_vertex(index_name, params)[source]

Queries for an edge in the index and returns the Response.

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:

RexsterResponse

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:

RexsterResponse

lookup_edge(index_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:

RexsterResponse

query_edge(index_name, params)[source]

Queries for an edge in the index and returns the Response.

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

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:

RexsterResponse

warm_cache()[source]

Warms the server cache by loading elements into memory.

RexsterRequest

class bulbs.rexster.client.RexsterRequest(config, content_type)[source]

Makes HTTP requests to Rexster and returns a RexsterResponse.

response_class

alias of RexsterResponse

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

RexsterResponse

class bulbs.rexster.client.RexsterResponse(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 RexsterResult objects, a single RexsterResult 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 RexsterResult

handle_response(http_resp)[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 RexsterResult objects, a single RexsterResult 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

RexsterResult

class bulbs.rexster.client.RexsterResult(result, config)[source]

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

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

Returns the element ID.

Return type:int or str
get_type()[source]

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

Return type:str
get_data()[source]

Returns the element’s property data.

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