Saengra
Python wrapper for Saengra graph database.
Quickstart: primitives and edges
Saengra is a graph database. It supports hashable Python objects (primitives) as graph
vertices. Built-in types like int or str can be used directly; also Saengra provides @primitive
decorator to declare dataclass-like types to be used as graph vertices.
Directed edges between primitives are always labelled with a string (edge label). It can be an arbitrary string, but the engine is optimized to support limited number of different labels per graph. There can't be two edges between the same two primitives with the same label.
We can construct a graph directly from primitives and edges by using elementary graph operations:
from datetime import datetime
from saengra import primitive, Environment
from saengra.graph import AddVertex, AddEdge
@primitive
class user:
id: int
u1 = user(id=1)
u2 = user(id=2)
u1_registered_at = datetime(2022, 1, 1, 12, 0, 0)
u2_registered_at = datetime(2023, 2, 3, 15, 0, 0)
env = Environment()
env.update(
AddVertex(u1),
AddVertex(u2),
AddVertex(u1_registered_at),
AddVertex(u2_registered_at),
AddEdge(u1, "follows", u2),
AddEdge(u1, "registered_at", u1_registered_at),
AddEdge(u2, "registered_at", u2_registered_at),
)
env.commit()
Quickstart: entities and environment
Operating with vertices and edges is tedious and slow. A higher-level abstraction, entities, is provided to make working with graph more like your normal object-oriented programming.
Let's declare some entity classes and rewrite the code above:
from datetime import datetime
from saengra import primitive, Entity, Environment
@primitive
class user:
id: int
class User(Entity, user):
registered_at: datetime
follows: set["User"]
env = Environment(entity_types=[User])
u1 = User.create(env, id=1, registered_at=datetime(2022, 1, 1, 12, 0, 0))
u2 = User.create(env, id=2, registered_at=datetime(2023, 2, 3, 15, 0, 0))
u1.follows.add(u2)
env.commit()
Quickstart: expressions and observers
Saengra introduces a domain-specific language to describe subgraphs of the graph, i.e. subset of vertices and edges. These expressions are quite similar to queries in SQL.
# Find all subscriptions, i.e. pairs (u1, u2) where u1 follows u2:
env.match("user as u1 -follows> user as u2")
# -> [{"u1": User(id=1), "u2": User(id=2)}]
# Find all mutual subscriptions:
env.match("user as u1 <follows> user as u2")
# -> []
But the most powerful aspect of Saengra is its observation capability. Saengra can match expressions incrementally after processing graph updates, and notify the program about created, changed and deleted subgraphs after each commit.
from saengra import observer
mutual_follow = observer("user as u1 <follows> user as u2")
@mutual_follow.on_create
def notify_mutuals(u1: User, u2: User):
print(f"{u1} is now mutuals with {u2}!")
env.register_observers([mutual_follow])
u2.follows.add(u1)
env.commit()
# -> User(id=1) is now mutuals with User(id=2)!
# -> User(id=2) is now mutuals with User(id=1)!
Generating Protobuf Code
The messages_pb2.py file is generated from the protobuf definitions in saengra-server/proto/messages.proto.
To regenerate:
protoc --python_out=saengra --proto_path=saengra-server/proto saengra-server/proto/messages.proto
Requirements:
protoc(Protocol Buffers compiler) must be installed- Python protobuf library:
pip install protobuf>=4.21.0
Usage
Option 1: Automatically start server
from saengra.client import SaengraClient
# Client automatically starts saengra-server in background
with SaengraClient() as client:
# Connect to a graph
created = client.connect("my_graph")
# Add vertices and edges
client.apply_updates([
# Your updates here
])
# Commit changes
response = client.commit()
The client expects saengra-server binary to be available in PATH.
Option 2: Connect to existing server
from saengra.client import SaengraClient
# Connect to an existing server socket
with SaengraClient(socket_path="/path/to/server.sock") as client:
# Connect to a graph
created = client.connect("my_graph")
# Work with the graph...
When using an existing socket, the client will not start or stop the server process, and will not clean up the socket file.
Metadata
Release files for saengra 0.1.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| saengra-0.1.16.tar.gz | 90.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| saengra-0.1.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details |
| saengra-0.1.16-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 | Details |
| saengra-0.1.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details |
| saengra-0.1.16-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 | Details |
Total release size: 18.1 MB
Release files / saengra-0.1.16.tar.gz
| Download URL | saengra-0.1.16.tar.gz |
|---|---|
| Size | 90.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86d8cb3dd0d52962eeddf92dfdc78fdc628a5e089d2a6589be4e8b7ba3496114
|
|
BLAKE2b-256 checksum How to use checksums |
2614c1d8729d3b26b3df714998e81c3665c83779fb40661665846ce6d3ff176b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / saengra-0.1.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | saengra-0.1.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
7b050a0ac2db938ecf38a83fbf8bc5245cad004b04f842f59737df379f4dd8cc
|
|
BLAKE2b-256 checksum How to use checksums |
a932f23a69397c848f6b66d5ca91d32cccd663fdcf3e24c90446be464060b4c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / saengra-0.1.16-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | saengra-0.1.16-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
d2f2c9a405e8bfdf02b418eec477a9644a376358917e53662bdca2ecee5e1079
|
|
BLAKE2b-256 checksum How to use checksums |
aa57a15d49084656619822df7b66127e8306c1cdbc9fcc875348cb0c3d3fc611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / saengra-0.1.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | saengra-0.1.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
ef2969212d6dede2bd8b7850e189a42c6df18bb0280189982e6aeb834f11e50d
|
|
BLAKE2b-256 checksum How to use checksums |
a2680796482142501464ec77649c65e2b872959682b0f4d0a004487c80958a03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / saengra-0.1.16-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | saengra-0.1.16-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
12d21e1095bf3e3f4753ece4f29484679c70c0b580b8a247205adc7adae4e32c
|
|
BLAKE2b-256 checksum How to use checksums |
b53fae93a5c1571c22a7dc8123c7e4dd94e58809c48595d5dbceb6b02ebd64d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency log