A Django module for managing hierarchical data models through a node tree, with kinship relationship queries and optional database-native optimisations.
Project description
Clade
A Django module for managing hierarchical data models through a tree of nodes, with kinship relationship queries and optional database-native optimisations.
Status
Pre-alpha — v0.3.0 published. API not yet stable.
| Version | Status | Content |
|---|---|---|
v0.3.0 |
✅ Current | LtreeField, PostgreSQL ltree backend, backend dispatch, integration tests |
v0.4.0 |
🔄 Next | Extended kinship (pibling, nibling, cousin) |
See the milestones and open issues on GitLab for the full roadmap.
What it does
Clade provides a Django application for modelling and querying tree-structured data. It exposes the full set of kinship relationships derivable from a node tree — not only parent/child pairs, but ancestors, descendants, siblings, and collateral lines (piblings, niblings, cousins…) — using gender-neutral terminology throughout.
It also introduces Affinity: a lateral relationship between nodes that share attribute values without any hierarchical link between them (planned for v0.5.0).
The module targets multiple database backends:
- PostgreSQL with
ltree— native optimisation (v0.3.0) - SQLite / other — pure-Django Materialized Path fallback (current)
Install
pip install django-clade
# settings.py
INSTALLED_APPS = [
...
"clade",
]
Usage
from clade.models import CladeNode
from django.db import models
class Category(CladeNode):
name = models.CharField(max_length=255)
# Build a tree
root = Category.objects.create(name="Root")
child = Category.objects.create(name="Child", parent=root)
leaf = Category.objects.create(name="Leaf", parent=child)
# Traverse
leaf.ancestors() # QuerySet → [root, child] (ordered by path)
root.descendants() # QuerySet → [child, leaf]
child.siblings() # QuerySet → []
leaf.is_root # False
leaf.is_leaf # True
leaf.root # → root
# Manager API
Category.objects.ancestors_of(leaf)
Category.objects.descendants_of(root)
# Deletion strategies
from clade.deletion import ADOPT
class Department(CladeNode):
name = models.CharField(max_length=255)
parent = models.ForeignKey(
"self", null=True, blank=True,
on_delete=ADOPT, # re-parents children on delete
related_name="children",
)
Requirements
- Python 3.10+
- Django 5.2+
Contributing
See CONTRIBUTING.md and CODE_OF_CONDUCT.md.
Licence
Apache License 2.0 — see LICENSE.txt and NOTICE.
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 django_clade-0.3.0.tar.gz.
File metadata
- Download URL: django_clade-0.3.0.tar.gz
- Upload date:
- Size: 50.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d2d1cc53e6eb028b7a5be941bd0a1372527b1f7552f9f3bfb4c64bc68d27e56
|
|
| MD5 |
6c24b932d0235973d252d5c93f3b0941
|
|
| BLAKE2b-256 |
716fd5fe9c5298f3ba7cc066a1f520fe99385826631f8b515a3051321853bec8
|
File details
Details for the file django_clade-0.3.0-py3-none-any.whl.
File metadata
- Download URL: django_clade-0.3.0-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bd77508e3e4dd263d0da15e24cc2857c5b3dc138b9d7b1a2d89e0507daea8f4
|
|
| MD5 |
d2063021f4f02961a38364451d692707
|
|
| BLAKE2b-256 |
ee17524d98ad0fc1bfec18cf88576428f83597558a5224aaa407e7d865584b8e
|