Skip to main content

sonnet-graph

Cypher graph database access for sonnet-server applications. It is the seam between the driver and a running process: pooling, lifecycle, readiness and in-graph metadata.

Version 0.3.1. It wraps cypher-graphdb>=0.5.0 and does not re-abstract it -- query building, result parsing, bulk loading, indexes and the differences between the two backends all stay in the driver. The backends are Apache AGE (on PostgreSQL) and Memgraph.

What it provides

  • GraphDBExtension -- pool lifecycle bound to the sonnet-server application lifecycle, with an optional mode for services where the graph is not required.
  • Pools -- named pools as the addressing scheme, borrow_graphdb() as the entry point and get_current_graphdb() for the ambient connection. Managed mode adds lazy creation and idle reaping when the set of graphs is open-ended.
  • Readiness and status -- GraphdbStage initialization and health checks on the sonnet-core readiness pipeline, plus pool snapshots for operations.
  • FastAPI dependencies -- get_graphdb() and get_graphdb_session() for router-level ambient connections.
  • Typed results -- per-pool model providers so query results come back as your own Pydantic classes.
  • Graph metadata -- stores that keep a graph's schema, documentation and named queries as nodes inside the graph itself.

It defines no SQLModel tables and ships no migrations.

Install

uv add sonnet-graph

Depends on sonnet-core, sonnet-server, cypher-graphdb, loguru and jinja2. The backend drivers arrive with cypher-graphdb, so there is no per-backend extra. The only extra is dev.

Usage

Register the extension once, then borrow a connection from anywhere in the process.

from sonnet_graph import GraphDBExtension, borrow_graphdb

registry = create_extension_registry(
    DatabaseExtension(),
    GraphDBExtension(),
)

with borrow_graphdb() as cdb:
    result = cdb.execute("MATCH (n:Product) RETURN n LIMIT 10")

GraphDBExtension(optional=True) skips startup instead of raising when the graph is unconfigured.

Configuration

The connection is configured through cypher-graphdb's own CGDB_ environment variables rather than being duplicated in consumer settings.

Variable Description
CGDB_BACKEND Backend type: age or memgraph
CGDB_CINFO Connection string / DSN
CGDB_GRAPH Graph name
CGDB_READ_ONLY Read-only mode (default: false)
CGDB_CREATE_GRAPH_IF_NOT_EXISTS Auto-create the graph, AGE only (default: false)

Documentation

License

Apache 2.0 -- see LICENSE.md.

Metadata

Release files for sonnet-graph 0.4.0

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

Source distribution (sdist)

Source distribution for sonnet-graph 0.4.0
File Size Uploaded Provenance Actions
sonnet_graph-0.4.0.tar.gz 29.1 kB With provenance Details for sonnet_graph-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sonnet-graph 0.4.0
File Interpreter ABI Platform Actions
sonnet_graph-0.4.0-py3-none-any.whl Python 3 none any Details for sonnet_graph-0.4.0-py3-none-any.whl

Total release size: 63.6 kB

Release files / sonnet_graph-0.4.0.tar.gz

Download URL sonnet_graph-0.4.0.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
100b06544825bfdbcdf0d1c13136870db582ea66a9770433592c3852e5d89349
BLAKE2b-256 checksum
How to use checksums
09f3f94cd65a1b64fd9c5a64eff8cc9a5fcb68fd134b11bbc5c0c087a1dc3e94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Release files / sonnet_graph-0.4.0-py3-none-any.whl

Download URL sonnet_graph-0.4.0-py3-none-any.whl
Size 34.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10eea05716bba77a5cc0c6d426d9240228db5a485e26b2fe11066612be34e52b
BLAKE2b-256 checksum
How to use checksums
d65145625efe9284217754406e5c98acb02a757474a7166b0914f50f13b040ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for sonnet-graph 0.4.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sonnet_graph-0.4.0.tar.gz

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 Nov 11, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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