Skip to main content

Graph queries that sit alongside your Django ORM

Project description

djraphdb

PyPI version Python versions Django versions License: MIT CI

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_transaction for 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 commandsgraph_info, graph_clear, graph_seed
  • Testing utilitiesGraphTestCase, MockGraphService, GraphFixtureLoader for easy testing
  • Django integrationINSTALLED_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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djraphdb-0.1.0.tar.gz (216.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djraphdb-0.1.0-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

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

Hashes for djraphdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec1507cffa3f31aac18663d94fc677c182c430ce3fc798ee655790317a0422c0
MD5 219a0dd487f41bd3f20b9f20d24918b3
BLAKE2b-256 628b441761989e59de1fa383ca72f61bb57c027ee1c0bb30d81838a4bb8ce799

See more details on using hashes here.

Provenance

The following attestation bundles were made for djraphdb-0.1.0.tar.gz:

Publisher: release.yml on josephbrockw/djraphdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for djraphdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf17f72d2367db403b2513bf0c42fd9b527fb83db9b2e5e30d4db4c184cb065f
MD5 7a77b6ba5cbea5b1841210a6a98eb75e
BLAKE2b-256 42e623b6ac51cd5b68399b1302330eba8916f221d9ff4c027e417663ccf0e563

See more details on using hashes here.

Provenance

The following attestation bundles were made for djraphdb-0.1.0-py3-none-any.whl:

Publisher: release.yml on josephbrockw/djraphdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page