Skip to main content
Gif of Ein from Cowboy Bebop in space

Note: I do not make any claims to the Cowboy Bebop assets, names, or trademarks.

Graph-Ein

A graph database implemented in SQLite. This is great for creating a standalone, single file graph database.

Badge for GitHub issues. Badge for GitHub forks. Badge for GitHub stars. Badge for GitHub license, MIT. Badge for sharable Twitter link. Pytest PyPI version

Installation

To install the project, run the following:

pip install ein-graph

Usage

The project generates a database file if one is not provided. The database itself is accessible; however, the Graph object is the typical interface that should be used for interacting with the data stored.

Database

SQLite database files are created for each separate database path that is provided. These are utilized upon instantiation of the Graph object, which will discover each of the data objects stored in the file.

The database can be connected to via DBeaver or some other database client if you'd like to explore the data.

Note: For users that want to utilize additional SQLite features there are methods for executing arbitrary statements/multiple statements.

Schemas

Databases have a concept of "schemas" that are used to organize disparate nodes and edges from each other. As such, a schema is needed for each of the node/edge data points added.

Schemas are stored in table-form as follows:

<schema_name>_nodes
<schema_name>_edges

To look at these in action use the following on your database using a database client:

-- from "select-schemas.sql"
SELECT
    name
FROM
    sqlite_master
WHERE
    type = 'table'
    AND
    tbl_name LIKE '%' || ? || '%'
;

Note: The above should only be used after a setup has been performed to create a client and add a schema.

Graph

The Graph instantiates with all current data in the supplied path.

Graphs operate with "schemas" that help to logically separate different sub-graphs. These graphs can be connected via Edge objects to bridge clusters of nodes.

Any data added/updated/deleted via the Graph is also reflected at the database level at time of execution.

from ein.graph import Graph


graph = Graph(db_path="test.db")
graph.add_schema("some_schema")

Nodes

Each Node object is a representation of data stored in the database, all data should be capable of being rendered to JSON.

from ein.node import Node


node = Node(
    schema_name="some_schema",
    id="my-id",
    body={
        "some-key": 1,
        "other-key": "data"
    },
)

Edges

The graph's Edges are a pair of nodes with a relationship. These contain the source and target nodes (and optionally properties for weights).

from ein.edge import Edge


edge = Edge(
    schema_name="some_schema",
    source=Node(...),
    target=Node(...),
)

To bridge Node objects between two schemas the schema_name= argument should be supplied. This will be the database schema that the edge is stored in, but the schemas of the source and target will be discovered from the Node objects.

from ein.edge import Edge


node_one = Node(
    schema_name="some_schema",
    ...,
)

node_two = Node(
    schema_name="some_other_schema",
    ...,
)

edge = Edge(
    schema_name=node_one.schema_name,
    source=node_one,
    target=node_two,
)

print(edge.source_schema_name) # some_schema
print(edge.target_schema_name) # some_other_schema

Releasing builds

To release builds for the project we use a combination of tagging and changes to setup.py.

For any releases to test.pypi.org use a change to the version="..." inside of setup.py. Once a PR is merged into the main project the test release will be updated.

Any prod releases to pypi.org require a tagged version number. This should be done locally by running the following:

git checkout master
git pull master
git tag v<version-number-here>
git push origin v<version-number-here>

Rollbacks of versions

To roll a version back we need to delete the tagged release from the prod PyPI, then delete the GitHub tag.

git tag -d v<version-number-here>
git push origin :v<version-number-here>

Release files for ein-graph 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ein-graph 0.0.12
File Size Uploaded
ein-graph-0.0.12.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ein-graph 0.0.12
File Interpreter ABI Platform
ein_graph-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / ein-graph-0.0.12.tar.gz

Download URL ein-graph-0.0.12.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2ffefc2c4e9b0b6f2febcd728edf4a3e957c55e51653e096845c12581055252c
BLAKE2b-256 checksum
How to use checksums
ff6c4c6f435cadc6ddf29e3f43b10c72ad32c43a92f58d703df4a3cee0621055
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / ein_graph-0.0.12-py3-none-any.whl

Download URL ein_graph-0.0.12-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01f07d429c05275e3e00290f3df46982b5383baaa089a25f5418f7078a43e7c5
BLAKE2b-256 checksum
How to use checksums
9b5f8fe495e296ea54c03dec6b835d9a3c339c93619e63ccff8755567958912a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page