Vert
Universal Graph Interface for Python
About
Vert is a Python package which attempts to provide a standardized interface for graphs. It does so by separating the graph into two separate layers of abstraction:
The graph store: This is where the graph is actually stored and represented. It may be a graph database, another graph library’s data structure, or one of vert’s built-in graph store objects.
The graph interface: This is where you, the programmer, can access the graph via an intuitive object-oriented interface using familiar data types such as Graph, Vertex, and Edge.
Because vert is structured along these distinct layers of abstraction, it is possible to write code that utilizes and operates on a graph without regard for the underlying storage mechanisms. Storage mechanisms can be freely swapped out for each other at the point where the graph object is initialized, and, aside from differences in performance and persistence, the rest of your code will never know the difference. Support for new graph storage mechanisms can be added simply by creating a class that supports the GraphStore interface. This means you never have to worry about vendor lock-in, and updating your code to use the latest technology is as simple as a one-line change.
Copyright/License
All content copyright 2017 Aaron M. Hosford. Use of this software is governed by the MIT license. See LICENSE.txt for the full license agreement.
Package Structure
test_vert: Unit tests for vert
test_stores: Unit tests for vert.stores
__init__.py: Empty placeholder.
_base.py: Contains base class for vert.stores test cases.
test_dbm.py: Unit tests for vert.stores.dbm.
test_memory.py: Unit tests for vert.stores.memory.
__init__.py: Empty placeholder.
vert: The package root
stores: Subpackage containing implementations of various graph stores that the vert package supports out of the box.
__init__.py: Empty placeholder.
base.py: Defines the GraphStore interface that all graph stores have to implement. The GraphStore interface hides the implementation details for each graph store, providing a consistent, albeit clunky, means of accessing and modifying the contents of a graph.
dbm.py: Defines DBMGraphStore, a DBM-backed persistent graph store.
memory.py: Defines the MemoryGraphStore, a non-persistent, memory-only graph store.
__init__.py: Exports the publicly visible symbols for the vert package. Nothing is actually defined in this module.
graphs.py: Defines the Graph, Vertex, and Edge, classes, along with other supporting infrastructure. This module’s classes transform the clunky interface provided by GraphStore into a convenient and versatile object-oriented interface designed to make it easy to work with graphs in a consistent manner regardless of how the underlying storage mechanisms work.
Examples
Non-Persistent
from vert import Graph
with Graph() as g:
dog = g.vertices['dog'].add()
cat = g.vertices['cat'].add()
edge = g.edges['dog', 'cat']
print(edge.exists) # False
edge.add()
print(edge.exists) # True
edge.labels.add('chases')
print('chases' in edge.labels) # True
with Graph() as g:
edge = g.edges['dog', 'cat']
print(edge.exists) # False
DBM-Backed Persistence
from vert import Graph
with Graph('test.db') as g:
dog = g.vertices['dog'].add()
cat = g.vertices['cat'].add()
edge = g.edges['dog', 'cat']
print(edge.exists) # False
edge.add()
print(edge.exists) # True
edge.labels.add('chases')
print('chases' in edge.labels) # True
with Graph('test.db') as g:
edge = g.edges['dog', 'cat']
print(edge.exists) # Still true
print('chases' in edge.labels) # Still true
Defining Your Own Storage Mechanism
from vert import Graph, GraphStore
class MyGraphStore(GraphStore):
# Implement each of GraphStore's abstract methods here
...
with Graph(MyGraphStore(...)) as g:
# Now the graph consults your back end for storage and retrieval
...
TODO:
Test cases for undirected edges.
Add separately installable graph stores for neo4j, tinkerpop, networkx, sqlite, and other back ends.
Add an example for creating a third-party module to provide support for new kinds of graph stores.
Add algorithms such as path finding and pattern matching. Whenever possible, these should be implemented by the graph store, rather than at the interface level. By having the interface classes inspect the graph store for the method before calling it, it should be possible to fall back on a slower default client-side implementation when the store does not provide one. An alternate approach would be to add the methods to the GraphStore class but have them raise a special sentinel exception if the particular implementation doesn’t provide the algorithm.
Add support for transactions and make the code thread-safe.
Add support for reading & writing common graph file formats.
Add support for transferring from one graph store to another.
100% code coverage for unit testing.
Continuous integration for unit testing.
Prettify the string representations for Edges and Vertices.
Make the DBM graph store more efficient.
Support older versions of Python.
Consider adding flags to GraphStore.iter_edges() for independent inclusion/exclusion of directed & undirected edges.
Add a rebuild() method to DBMGraphStore which ensures the stored graph is in a consistent state through minimum modifications, allowing recovery from disk or power failure.
Metadata
Release files for vert 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| vert-1.0.1.tar.gz | 21.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vert-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.8 kB
Release files / vert-1.0.1.tar.gz
| Download URL | vert-1.0.1.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9e7280f19cca372a8e7f36ab2a9508ad7f486f4cbdcbcf3cc242617b6bc41b4
|
|
BLAKE2b-256 checksum How to use checksums |
666846adaba694eff1b52ffa000b64b045ae58df30c2e96769e7eacbfd5b3b21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / vert-1.0.1-py3-none-any.whl
| Download URL | vert-1.0.1-py3-none-any.whl |
|---|---|
| Size | 26.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d56672830800535204605681320c1c656ce733073d731d8ecbbf7355d0335a9
|
|
BLAKE2b-256 checksum How to use checksums |
d52cc1a775b9d53d76f3426c8c860e183f97caa1b105ac2fe69df34585f04e6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for vert 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.