Bulbs API

Bulbs is an open-source Python library and persistence framework for graph databases. It connects to Rexster, which provides access to any Blueprints-enabled graph database, including: TinkerGraph, Neo4j, OrientDB, Dex, and OpenRDF Sail.

Graph

class bulbs.neo4jserver.graph.Neo4jGraph(root_uri='http://localhost:7474/db/data/')[source]

The primary interface to graph databases on the Rexster REST server.

Instantiates the database Resource object using the specified database URL and sets up proxy objects to the database.

Parameters:root_uri – The URI to Neo4j Server.

Example:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> james = g.vertices.create({'name':'James'})
>>> julie = g.vertices.create({'name':'Julie'})
>>> g.edges.create(james,"knows",julie)
>>> g.vertices.index.lookup(name="James")
load_graphml(uri)[source]

Loads a GraphML file into the database and returns the response.

save_graphml()[source]

Returns a GraphML file representing the entire database.

clear()[source]

Deletes all the elements in the graph.

WARNING

g.clear() will delete all your data!

Vertices

class bulbs.element.Vertex(resource)[source]

A container for Vertex elements returned by the resource.

outE(label=None)[source]

Return the outgoing edges of the vertex.

inE(label=None)[source]

Return the incoming edges of the vertex.

bothE(label=None)[source]

Return all incoming and outgoing edges of the vertex.

outV(label=None)[source]

Return the out-adjacent vertices to the vertex.

inV(label=None)[source]

Return the in-adjacent vertices of the vertex.

bothV(label=None)[source]

Return all incoming- and outgoing-adjacent vertices of vertex.

map()

Returns a dict of the element’s data that’s stored in the DB.

class bulbs.element.VertexProxy(element_class, resource)[source]

A proxy for interacting with vertices on the Resource.

create(data={})[source]

Adds an element to the database and returns it.

get(_id)[source]

Retrieves an element from the database and returns it.

update(_id, data)[source]

Updates an element in the graph DB and returns it.

delete(_id)[source]

Deletes a vertex from a graph DB and returns the response.

remove_properties(_id)[source]

Removes all properties from a element and returns the response.

Edges

class bulbs.element.Edge(resource)[source]

A container for Edge elements returned by the resource.

outV()[source]

Returns the outgoing Vertex of the edge.

inV()[source]

Returns the incoming Vertex of the edge.

map()

Returns a dict of the element’s data that’s stored in the DB.

class bulbs.element.EdgeProxy(element_class, resource)[source]

A proxy for interacting with edges on the Resource.

create(outV, label, inV, data={})[source]

Adds an edge to the database and returns it.

get(_id)[source]

Retrieves an element from the Resource and returns it.

delete(_id)[source]

Deletes a vertex from a graph DB and returns the response.

remove_properties(_id)[source]

Removes all properties from a element and returns the response.

Indices

class bulbs.index.Index(resource, results)[source]

Abstract base class for the default index.

resource = None

The Resource object for the database.

results = None

The index attributes returned by the proxy request.

index_name[source]

Returns the index name.

put(_id, key=None, value=None, **pair)[source]

Put an element into the index at key/value and return the response.

put_unique(_id, key=None, value=None, **pair)[source]

Put an element into the index at key/value and overwrite it if an element already exists at that key and value; thus, there will be a max of 1 element returned for that key/value pair. Return Rexster’s response.

update(_id, key=None, value=None, **pair)[source]

Update the element ID for the key and value.

get(key=None, value=None, **pair)[source]

Return all the elements in the index with property key equal to value.

get_unique(key=None, value=None, **pair)[source]

Returns a max of 1 elements matching the key/value pair in the index.

remove(_id, key=None, value=None, **pair)[source]

Remove the element from the index located by key/value.

count(key=None, value=None, **pair)[source]

Returns the number of items in the index for the key/value pair.

class bulbs.index.VertexIndexProxy(index_class, resource)[source]

Abstract base class the vertex index proxy.

index_class = None

The index class for this proxy, e.g. ExactIndex.

resource = None

The Resource object for the database.

create(index_name)[source]

Creates an an index and returns it.

get(index_name)[source]

Returns the Index object with the specified name or None if not found.

delete(index_name)[source]

Deletes/drops an index and returns the Rexster Response object.

class bulbs.index.EdgeIndexProxy(index_class, resource)[source]

Abstract base class the edge index proxy.

index_class = None

The index class for this proxy, e.g. ExactIndex.

resource = None

The Resource object for the database.

create(index_name)[source]

Creates an an index and returns it.

get(index_name)[source]

Returns the Index object with the specified name or None if not found.

delete(index_name)[source]

Deletes/drops an index and returns the Rexster Response object.

Gremlin

class bulbs.gremlin.Gremlin(resource)[source]

An interface for executing Gremlin scripts on the resource.

command(script, params=None)[source]

Returns raw results of an arbitrary Gremlin command.

Parameters:
  • script – Gremlin script to send to the resource.
  • params – Paramaters to bind to the Gremlin script.
query(script, params=None)[source]

Returns initialized results of an arbitrary Gremlin query.

Parameters:
  • script – Gremlin script to send to the resource.
  • params – Paramaters to bind to the Gremlin script.

Model

class bulbs.model.Node(resource)[source]
save()[source]

Saves/updates the element’s data in the database.

bothE(label=None)

Return all incoming and outgoing edges of the vertex.

bothV(label=None)

Return all incoming- and outgoing-adjacent vertices of vertex.

inE(label=None)

Return the incoming edges of the vertex.

inV(label=None)

Return the in-adjacent vertices of the vertex.

map()

Returns a dict of the element’s data that’s stored in the DB.

outE(label=None)

Return the outgoing edges of the vertex.

outV(label=None)

Return the out-adjacent vertices to the vertex.

class bulbs.model.Relationship(resource)[source]
save()[source]

Saves/updates the element’s data in the database.

inV()

Returns the incoming Vertex of the edge.

map()

Returns a dict of the element’s data that’s stored in the DB.

outV()

Returns the outgoing Vertex of the edge.

Properties

class bulbs.property.Property(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]

Container for a graph-database property used to create Models.

validate(key, value)[source]

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.String(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of str

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.Integer(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of int

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.Long(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of long

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.Float(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of float

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.Null(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.List(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of list

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

class bulbs.property.Dictionary(name=None, fget=None, fset=None, fdel=None, default=None, onupdate=None, constraint=None, nullable=True, unique=False, index=False)[source]
python_type

alias of dict

validate(key, value)

Validates that Property data is of the right datatype before saving it to the DB and that the Property has a value if nullable is set to False.

Resource

class bulbs.resource.Resource(config)[source]

Abstract base class for a server resource.

Parameters:config – Config object containing instance-specific configuration.
config = None

Config object containing instance-specific configuration.

registery = None

Registry object to hold classes, proxies, indices, and scripts.

gremlin(script, params=None)[source]

Executes a Gremlin script and returns the Response.

create_vertex(data)[source]

Creates a vertex and returns the Response.

get_vertex(_id)[source]

Gets the vertex with the _id and returns the Response.

update_vertex(_id, data)[source]

Updates the vertex with the _id and returns the Response.

delete_vertex(_id)[source]

Deletes a vertex with the _id and returns the Response.

create_edge(outV, label, inV, data={})[source]

Creates a edge and returns the Response.

get_edge(_id)[source]

Gets the edge with the _id and returns the Response.

update_edge(_id, data)[source]

Updates the edge with the _id and returns the Response.

delete_edge(_id)[source]

Deletes a edge with the _id and returns the Response.

outE(_id, label=None)[source]

Returns the outgoing edges of the vertex.

inE(_id, label=None)[source]

Returns the incoming edges of the vertex.

bothE(_id, label=None)[source]

Returns the outgoing and incoming edges of the vertex.

outV(_id, label=None)[source]

Returns the adjacent outgoing vertices of the vertex.

inV(_id, label=None)[source]

Returns the adjacent incoming vertices of the vertex.

bothV(_id, label=None)[source]

Returns the adjacent outgoing and incoming vertices of the vertex.

create_vertex_index(params)[source]

Creates a vertex index with the specified params.

get_vertex_index(index_name)[source]

Returns the vertex index with the index_name.

delete_vertex_index(index_name)[source]

Deletes the vertex index with the index_name.

create_edge_index(params)[source]

Creates a edge index with the specified params.

get_edge_index(index_name)[source]

Returns the edge index with the index_name.

delete_edge_index(index_name)[source]

Deletes the edge index with the index_name.

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

Adds a vertex to the index with the index_name.

lookup_vertex(index_name, key, value)[source]

Returns the vertices indexed with the key and value.

query_vertex(index_name, params)[source]

Returns the vertices for the index query.

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

Removes a vertex from the index and returns the Response.

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

Adds an edge to the index and returns the Response.

lookup_edge(index_name, key, value)[source]

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

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.

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

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

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

Updates an indexed vertex and returns the Response.

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

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

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

Updates an indexed edge and returns the Response.

warm_cache()[source]

Warms the server cache by loading elements into memory.

Response

class bulbs.resource.Response(response, config)[source]

Abstract base class for the response returned by the request.

Parameters:response – The raw response; its type will depend on the Resource.
result_class

alias of Result

content = None

A dict containing the content returned in the response.

raw = None

The raw response returned by the request.

handle_response(response)[source]

Check the server response and raise exceptions if needed.

get_content(response)[source]

Return a dict containing the content returned in the response.

get_results()[source]

Return a Result object or a generator of Result objects.

get(attribute)[source]

Return a resource-specific attribute.