The main distinguishing factor for this project is that it can retrieve entire sections of a graph with far fewer queries than most other packages. The trade off is portability: it uses Postgres' Common Table Expressions (CTE) to achieve this and is therefore not compatible with other databases.
The primary purpose of this package is to build and manipulate DAGs within a Django project. If you are looking for graph analysis or visualization, this may not be the right package.
All core traversal methods (ancestors(), descendants(), path(), connected_graph(), tree methods, roots(), leaves(), edge queries, etc.) use CTE-based queries.
The package also supports CTE filters (disallow_nodes, allow_nodes, disallow_edges, allow_edges, limiting_edges_set_fk) to limit the area of the graph searched, and optional NetworkX/RustworkX/JSON export via the transforms extra. Manager-level methods connected_components() and graph_stats() provide whole-graph analytics. All traversal and predicate methods accept a convenient edge_type parameter as shorthand for limiting_edges_set_fk.
Additional graph algorithms include: topological sort, depth annotation, all-paths enumeration, lowest common ancestor (LCA), weighted shortest path, critical path (longest path), transitive reduction, and graph hashing (via NetworkX Weisfeiler-Lehman).
Quickstart example | Tutorial | Full documentation
pip install django-postgresql-dag
With optional dependencies for using transformations:
pip install django-postgresql-dag[transforms]
You can optionally configure the default maximum traversal depth for all graph queries by adding this to your Django settings:
# settings.py
DJANGO_POSTGRESQL_DAG_MAX_DEPTH = 50 # default is 20This sets the project-wide default for all graph traversal methods (ancestors(), descendants(), path(), etc.). You can still override it per-call by passing max_depth=N to any method.
See the checklists in issues to understand the future goals of this project.