Skip to main content

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.

pipeline status coverage PyPI License


Status

Pre-alphav0.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


Download files

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

Source Distribution

django_clade-0.3.0.tar.gz (50.8 kB view details)

Uploaded Source

Built Distribution

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

django_clade-0.3.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

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

Hashes for django_clade-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6d2d1cc53e6eb028b7a5be941bd0a1372527b1f7552f9f3bfb4c64bc68d27e56
MD5 6c24b932d0235973d252d5c93f3b0941
BLAKE2b-256 716fd5fe9c5298f3ba7cc066a1f520fe99385826631f8b515a3051321853bec8

See more details on using hashes here.

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

Hashes for django_clade-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bd77508e3e4dd263d0da15e24cc2857c5b3dc138b9d7b1a2d89e0507daea8f4
MD5 d2063021f4f02961a38364451d692707
BLAKE2b-256 ee17524d98ad0fc1bfec18cf88576428f83597558a5224aaa407e7d865584b8e

See more details on using hashes here.

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