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.4.0 published. API not yet stable.
| Version | Status | Content |
|---|---|---|
v0.4.0 |
✅ Current | Extended kinship (pibling, nibling, cousin — symmetric degree) |
v0.5.0 |
🔄 Next | Affinity model & storage decision (DD-005) |
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",
)
# Extended kinship (v0.4.0) — pibling, nibling, cousin
grandparent = Category.objects.create(name="Grandparent")
parent = Category.objects.create(name="Parent", parent=grandparent)
aunt = Category.objects.create(name="Aunt", parent=grandparent)
me = Category.objects.create(name="Me", parent=parent)
cousin = Category.objects.create(name="Cousin", parent=aunt)
me.piblings() # QuerySet → [aunt] (siblings of my parent)
aunt.niblings() # QuerySet → [me] (children of my siblings)
me.cousins() # QuerySet → [cousin] (degree=2, the default)
# Manager API
Category.objects.piblings_of(me)
Category.objects.cousins_of(me, degree=2)
cousins()/cousins_of() use a symmetric degree, not the genealogical
(degree, removed) convention: degree=2 (the default) matches "1st cousin";
degree=3 matches "2nd cousin". Candidates at a different depth than the
node itself (genealogically "once removed", etc.) are not covered — see
issue #56 for the full
rationale and the planned post-v1.0.0 extension.
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.
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.4.0.tar.gz.
File metadata
- Download URL: django_clade-0.4.0.tar.gz
- Upload date:
- Size: 57.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 |
209cd4724cc7b5b0df31f9afcbb312024b0972da87d762c861aa03ec459e0455
|
|
| MD5 |
374882a74fdb4161e59ea04d47847371
|
|
| BLAKE2b-256 |
1e9e8bf9a3b982783965f2348574cf26a7c9b241fddf6b0ea949781a569cbfcb
|
File details
Details for the file django_clade-0.4.0-py3-none-any.whl.
File metadata
- Download URL: django_clade-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 |
e9f7c4d14f5f06a86ae73c80ca5904e2bc924bfa4c7c1bb069638a8bf3d1d57e
|
|
| MD5 |
35ce58a43118300387751c89eec809a0
|
|
| BLAKE2b-256 |
6ac63b840a4887b1abd82fb4277d8f60441bbd039862575f949a8b09fcc7f1ab
|