Graph queries that sit alongside your Django ORM
Project description
djraphdb
Graph queries that sit alongside your Django ORM.
djraphdb is a clean, idiomatic service layer for using Neo4j alongside Django's relational ORM.
It is not a database backend — it is a parallel query interface that respects Django conventions
while embracing Cypher and graph-native patterns. You keep your existing Django models and
migrations; djraphdb gives your Neo4j queries the same first-class treatment.
Features
- Multi-database connections — manage multiple named Neo4j connections with connection pooling and retry
- GraphService — clean read/write/transaction API with typed result mapping (dataclasses, NamedTuples, Pydantic)
- GraphNode — declarative ORM-style node models with field descriptors and CRUD operations
- CypherQuery builder — fluent query builder with first-class
.raw()support for complex Cypher - Decorators —
@graph_read,@graph_write,@graph_transactionfor declarative graph access in views - Middleware — per-request session and transaction scoping
- Health checks — connectivity probes, Django system checks, and an optional health endpoint
- Signals — Django signals for query execution, slow queries, and connection lifecycle
- Management commands —
graph_info,graph_clear,graph_seed - Testing utilities —
GraphTestCase,MockGraphService,GraphFixtureLoaderfor easy testing - Django integration —
INSTALLED_APPS, app lifecycle hooks, settings system
Why djraphdb?
| djraphdb | neomodel | Raw neo4j driver | |
|---|---|---|---|
| Django integration | ✓ Full | Partial | None |
| Multi-database | ✓ | ✗ | Manual |
| Raw Cypher | ✓ First-class | Limited | ✓ |
| Type-safe results | ✓ | Partial | ✗ |
| Testing utilities | ✓ | ✗ | ✗ |
| Django signals | ✓ | ✗ | ✗ |
| Health checks | ✓ | ✗ | ✗ |
| ORM replacement | ✗ (by design) | Partial | ✗ |
Why not a full Django database backend?
Django's ORM assumes relational algebra: tables, foreign keys, GROUP BY. Mapping these concepts to Neo4j's graph model would be a leaky abstraction requiring months of work. djraphdb takes a pragmatic approach: a clean service layer that sits alongside your existing Django ORM, giving graph queries a first-class API without fighting the relational model.
Quickstart
pip install djraphdb
Add "djraphdb" to your INSTALLED_APPS and configure the connection:
# settings.py
import os
INSTALLED_APPS = [
...
"djraphdb",
]
DJRAPHDB = {
"URI": os.environ["NEO4J_URI"],
"AUTH": (os.environ["NEO4J_USER"], os.environ["NEO4J_PASSWORD"]),
"DATABASE": "neo4j",
}
Run your first query:
from djraphdb.service import GraphService
service = GraphService()
people = service.read("MATCH (p:Person) RETURN p.name AS name, p.age AS age")
Declare a node model:
from djraphdb.nodes import GraphNode
from djraphdb.fields import StringProperty, IntegerProperty, UUIDProperty
class Person(GraphNode):
uid = UUIDProperty()
name = StringProperty(required=True)
age = IntegerProperty()
alice = Person(name="Alice", age=30)
alice.save()
alice = Person.nodes.get(name="Alice")
Documentation
Full documentation: djraphdb.readthedocs.io
- Getting Started — full tutorial
- Configuration — all
DJRAPHDBsettings - GraphService — primary query interface
- GraphNode — declarative node models
- Query Builder — CypherQuery API
- Testing — GraphTestCase, fixtures, MockGraphService
See CHANGELOG.md for the full version history.
Development
Clone the repo and install dev dependencies:
git clone https://github.com/josephbrockw/djraphdb.git
cd djraphdb
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
| Command | What it does |
|---|---|
make test |
Run unit tests (no Docker required) |
make test-integration |
Run integration tests (requires Docker) |
make test-all |
Run all tests |
make lint |
Run ruff check and mypy |
See docs/contributing.md for the full development guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djraphdb-0.1.0.tar.gz.
File metadata
- Download URL: djraphdb-0.1.0.tar.gz
- Upload date:
- Size: 216.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec1507cffa3f31aac18663d94fc677c182c430ce3fc798ee655790317a0422c0
|
|
| MD5 |
219a0dd487f41bd3f20b9f20d24918b3
|
|
| BLAKE2b-256 |
628b441761989e59de1fa383ca72f61bb57c027ee1c0bb30d81838a4bb8ce799
|
Provenance
The following attestation bundles were made for djraphdb-0.1.0.tar.gz:
Publisher:
release.yml on josephbrockw/djraphdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djraphdb-0.1.0.tar.gz -
Subject digest:
ec1507cffa3f31aac18663d94fc677c182c430ce3fc798ee655790317a0422c0 - Sigstore transparency entry: 992082903
- Sigstore integration time:
-
Permalink:
josephbrockw/djraphdb@708855ea8ef6ba652e2ee87fce69b6102dbbe513 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/josephbrockw
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@708855ea8ef6ba652e2ee87fce69b6102dbbe513 -
Trigger Event:
push
-
Statement type:
File details
Details for the file djraphdb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: djraphdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf17f72d2367db403b2513bf0c42fd9b527fb83db9b2e5e30d4db4c184cb065f
|
|
| MD5 |
7a77b6ba5cbea5b1841210a6a98eb75e
|
|
| BLAKE2b-256 |
42e623b6ac51cd5b68399b1302330eba8916f221d9ff4c027e417663ccf0e563
|
Provenance
The following attestation bundles were made for djraphdb-0.1.0-py3-none-any.whl:
Publisher:
release.yml on josephbrockw/djraphdb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djraphdb-0.1.0-py3-none-any.whl -
Subject digest:
bf17f72d2367db403b2513bf0c42fd9b527fb83db9b2e5e30d4db4c184cb065f - Sigstore transparency entry: 992082940
- Sigstore integration time:
-
Permalink:
josephbrockw/djraphdb@708855ea8ef6ba652e2ee87fce69b6102dbbe513 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/josephbrockw
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@708855ea8ef6ba652e2ee87fce69b6102dbbe513 -
Trigger Event:
push
-
Statement type: