Skip to main content

Treenode Framework for supporting tree (hierarchical) data structure in Django projects

Project description

Treenode Framework

A hybrid open-source framework for working with trees in Django

Tests Docs PyPI Published on Django Packages Sponsor

About The Treenode Framework

Overview

Treenode Framework is an advanced tree management system for Django applications. It is designed to handle large-scale, deeply nested, and highly dynamic tree structures while maintaining excellent performance, data integrity, and ease of use.

Unlike traditional solutions, Treenode Framework is built for serious real-world applications where trees may consist of:

  • Number nodes to 50-100 thousands nodes,
  • Nesting depths to 1,000 levels,
  • Complex mutation patterns (bulk moves, merges, splits),
  • Real-time data access via API.

Its core philosophy: maximum scalability, minimum complexity.

Key Features

Common operations

The django-fast-treenode package supports all the basic operations needed to work with tree structures:

  • Extracting ancestors (queryset, list, pks, count);
  • Extracting children (queryset, list, pks, count);
  • Extracting descendants (queryset, list, pks, count);
  • Extracting a family: ancestors, the node itself and its descendants (queryset, list, pks, count);
  • Enumerating all the nodes (queryset, dicts);
  • Adding a new node at a certain position on the tree;
  • Automatic sorting of node order by the value of the specified field;
  • Deleting an node;
  • Pruning: Removing a whole section of a tree;
  • Grafting: Adding a whole section to a tree;
  • Finding the root for any node;
  • Finding the lowest common ancestor of two nodes;
  • Finding the shortest path between two nodes.

Due to its high performance and ability to support deep nesting and large tree sizes, the django-fast-treenode package can be used for any tasks that involve the use of tree-like data, with virtually no restrictions.

Where Massive Trees Really Matter?

Treenode Framework is designed to handle not only toy examples, but also real trees with strict requirements for the number of nodes and their nesting.

Typical applications include:

  • Digital Twin Systems for industrial asset management (plants, machinery, vehicles), where full structural decomposition is critical for maintenance planning and cost optimization.
  • Decision Support Systems in medicine, law, and insurance, where large and dynamic decision trees drive critical reasoning processes.
  • AI Planning Engines based on hierarchical task networks, allowing intelligent agents to decompose and execute complex strategies.
  • Biological and Genetic Research, where large phylogenetic trees model evolutionary relationships or genetic hierarchies.

In all these domains, scalable and fast tree management is not a luxury — it's a necessity.

Why Treenode Framework?

At the moment, django-fast-treenode is, if not the best, then one of the best packages for working with tree data under Django.

  • High performance: tests show that on trees of 5k-10k nodes with a nesting depth of 500-600 levels, Treenode Framework (django-fast-treenode) shows performance 4-7 times better than the main popular packages.
  • Flexible API: today contains the widest set of methods for working with a tree in comparison with other packages.
  • Convenient administration: the admin panel interface was developed taking into account the experience of using other packages. It provides convenience and intuitiveness with ease of programming.
  • Scalability: Treenode Framework suitable for solving simple problems such as menus, directories, parsing arithmetic expressions, as well as complex problems such as program optimization, image layout, multi-step decision making problems, or machine learning..
  • Lightweight: All functionality is implemented within the package without heavyweight dependencies such as djangorestframework or django-import-export.
  • Optional JWT authentication: enable token-based protection for the API with a single setting.

All this makes Treenode Framework a prime candidate for your needs.

Quick Start

To get started quickly, you need to follow these steps:

  • Simply install the package via pip:

    pip install django-fast-treenode
    
  • Once installed, add 'treenode' to your INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        ...
        'treenode',
        ...
    ]
    
  • Open models.py and create your own tree class:

    from treenode.models import TreenodeModel
    
    class MyTree(TreenodeModel):
      name = models.CharField(max_length=255)
      display_field = "name"
    
  • Open admin.py and create a model for the admin panel

    from django.contrib import admin
    from treenode.admin import TreenodeModelAdmin
    from .models import MyTree
    
    @admin.register(MyTree)
    class MyTreeAdmin(TreenodeModelAdmin):
      list_display = ("name",)
      search_fields = ("name",)
    
  • Then, apply migrations:

    python manage.py makemigrations
    python manage.py migrate
    
  • Run server

    python manage.py runserver
    

Everything is ready, enjoy 🎉!

Documentation

Full documentation is available at ReadTheDocs.

Quick access links:

Your wishes, objections, comments are welcome.

License

Released under MIT License.

Credits

Thanks to everyone who contributed to the development and testing of this package, as well as the Django community for their inspiration and support.

Special thanks to Fabio Caccamo for the idea behind creating a fast Django application for handling hierarchies.

Also special thanks to everyone who supports the project with their sponsorship donations.

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_fast_treenode-3.2.8.tar.gz (336.9 kB view details)

Uploaded Source

Built Distribution

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

django_fast_treenode-3.2.8-py3-none-any.whl (290.8 kB view details)

Uploaded Python 3

File details

Details for the file django_fast_treenode-3.2.8.tar.gz.

File metadata

  • Download URL: django_fast_treenode-3.2.8.tar.gz
  • Upload date:
  • Size: 336.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for django_fast_treenode-3.2.8.tar.gz
Algorithm Hash digest
SHA256 969aff2e2d2b9b0c0a846aec55d71b2ed9612bd3d6c11bb76a08f02be4d3e85d
MD5 b220f123495ee34f197d76547e9fbee1
BLAKE2b-256 2fbdff3fbf532d99f90b85d9acba165dada6eb44e793d96f5811765ede27c71a

See more details on using hashes here.

File details

Details for the file django_fast_treenode-3.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_fast_treenode-3.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 2fed2183352a50f5967f75a3037fa605ad4b921655aff218eb0f8618191fd09d
MD5 06fba3e1d6b1bd787c759607e0596402
BLAKE2b-256 35303d1ac0218cecd448babe027358973dabc03a89aa5e5a4169567af9252094

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