Client¶
Open-source Python library for graph databases.
Client¶
- class bulbs.base.client.Client(config=None)[source]¶
Abstract base class for the low-level server client.
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.
- type_system – TypeSystem object.
- request – Request object.
Example:
>>> from bulbs.neo4jserver import Neo4jClient >>> client = Neo4jClient() >>> script = client.scripts.get("get_vertices") >>> response = client.gremlin(script, params=None) >>> result = response.results.next()
- create_vertex(data)[source]¶
Creates a vertex and returns the Response.
Parameters: data (dict) – Property data. Return type: Response
- get_vertex(_id)[source]¶
Gets the vertex with the _id and returns the Response.
Parameters: data (int) – Vertex ID. Return type: Response
- get_all_vertices()[source]¶
Returns a Response containing all the vertices in the Graph.
Return type: Response
- 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: Response
- delete_vertex(_id)[source]¶
Deletes a vertex with the _id and returns the Response.
Parameters: _id (dict) – Vertex ID. Return type: Response
- 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: Response
- get_edge(_id)[source]¶
Gets the edge with the _id and returns the Response.
Parameters: data (int) – Edge ID. Return type: Response
- get_all_edges()[source]¶
Returns a Response containing all the edges in the Graph.
Return type: Response
- 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: Response
- delete_edge(_id)[source]¶
Deletes a edge with the _id and returns the Response.
Parameters: _id (dict) – Edge ID. Return type: Response
- outE(_id, label=None)[source]¶
Returns the outgoing edges of the vertex.
Parameters: - _id (dict) – Vertex ID.
- label (str) – Optional edge label. Defaults to None.
Return type: Response
- inE(_id, label=None)[source]¶
Returns the incoming edges of the vertex.
Parameters: - _id (dict) – Vertex ID.
- label (str) – Optional edge label. Defaults to None.
Return type: Response
- bothE(_id, label=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: Response
- outV(_id, label=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: Response
- inV(_id, label=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: Response
- bothV(_id, label=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: Response
- create_vertex_index(params)[source]¶
Creates a vertex index with the specified params.
Parameters: index_name (str) – Name of the index to create. Return type: Response
- get_vertex_index(index_name)[source]¶
Returns the vertex index with the index_name.
Parameters: index_name (str) – Name of the index. Return type: Response
- delete_vertex_index(index_name)[source]¶
Deletes the vertex index with the index_name.
Parameters: index_name (str) – Name of the index. Return type: Response
- create_edge_index(index_name)[source]¶
Creates a edge index with the specified params.
Parameters: index_name (str) – Name of the index. Return type: Response
- get_edge_index(index_name)[source]¶
Returns the edge index with the index_name.
Parameters: index_name (str) – Name of the index. Return type: Response
- delete_edge_index(index_name)[source]¶
Deletes the edge index with the index_name.
Parameters: index_name (str) – Name of the index. Return type: Response
- 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: Response
- 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: 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: Response
- 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: Response
- 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: 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: Response
- 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: Response
- 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: Response
- create_indexed_edge(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: Response
- 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: Response
Response¶
- class bulbs.base.client.Response(response, config)[source]¶
Abstract base class for the response returned by the request.
Parameters: - response (Depends on Client.) – The raw response.
- config (bulbs.config.Config) – Config object.
Variables: - config – Config object.
- headers – Response headers.
- content – A dict containing the 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 Result
- handle_response(response)[source]¶
Check the server response and raise exception if needed.
Parameters: response (Depends on Client.) – Raw server response. Return type: None
- get_headers(response)[source]¶
Returns a dict containing the headers from the response.
Parameters: response (tuple) – Raw server response. Return type: httplib2.Response
- get_content(response)[source]¶
Returns a dict containing the content from the response.
Parameters: response (tuple) – Raw server response. 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