Metadata-Version: 2.4
Name: django-postgresql-dag
Version: 2026.2.1
Summary: Directed Acyclic Graph implementation for Django & Postgresql
Author-email: Jack Linke <jack@watervize.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/OmenApps/django-postgresql-dag
Project-URL: Repository, https://github.com/OmenApps/django-postgresql-dag
Project-URL: Documentation, https://django-postgresql-dag.readthedocs.io/en/latest/
Project-URL: Issues, https://github.com/OmenApps/django-postgresql-dag/issues
Keywords: django,graph,tree,dag,network,directed,acyclic,postgres,cte
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Database
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django>=4.2
Requires-Dist: psycopg[binary]>=3.1
Provides-Extra: transforms
Requires-Dist: networkx>=2.5; extra == "transforms"
Requires-Dist: pandas>=1.2; extra == "transforms"
Requires-Dist: rustworkx>=0.13; extra == "transforms"
Dynamic: license-file

[![codecov](https://codecov.io/gh/OmenApps/django-postgresql-dag/branch/master/graph/badge.svg?token=IJRBEE6R0C)](https://codecov.io/gh/OmenApps/django-postgresql-dag) ![PyPI](https://img.shields.io/pypi/v/django-postgresql-dag?color=green) ![last commit](https://badgen.net/github/last-commit/OmenApps/django-postgresql-dag/main) [![Documentation Status](https://readthedocs.org/projects/django-postgresql-dag/badge/?version=latest)](http://django-postgresql-dag.readthedocs.io/) [![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)

# Django & Postgresql-based Directed Acyclic Graphs

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`.

## Demo

[Quickstart example](https://django-postgresql-dag.readthedocs.io/en/latest/quickstart.html)

## Install

    pip install django-postgresql-dag

With optional dependencies for using transformations:

    pip install django-postgresql-dag[transforms]


## Configuration

You can optionally configure the default maximum traversal depth for all graph queries by adding this to your Django settings:

```python
# settings.py
DJANGO_POSTGRESQL_DAG_MAX_DEPTH = 50  # default is 20
```

This 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.

## ToDo

See the checklists in [issues](https://github.com/OmenApps/django-postgresql-dag/issues) to understand the future goals of this project.


## Credits:

1. [This excellent blog post](https://www.fusionbox.com/blog/detail/graph-algorithms-in-a-database-recursive-ctes-and-topological-sort-with-postgres/620/)
2. [django-dag](https://pypi.org/project/django-dag/)
3. [django-dag-postgresql](https://github.com/worsht/django-dag-postgresql)
4. [django-treebeard-dag](https://pypi.org/project/django-treebeard-dag/)
