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.10.tar.gz (340.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_fast_treenode-3.2.10-py3-none-any.whl (296.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_fast_treenode-3.2.10.tar.gz
  • Upload date:
  • Size: 340.8 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.10.tar.gz
Algorithm Hash digest
SHA256 3154b4ca7afa4efea410625ae65baecc7ebd697db76b1985d84456a26d5ac6fe
MD5 6c35ec7e1d7fe57e9086abd7781f89cf
BLAKE2b-256 3d196d054f1a74ad93d6cf92c16a11e1b10609b5272e531e5e51662369524e98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_fast_treenode-3.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6386197598ae5073b95bb6902e1cb55f24ee3d869c058f2019906e99ad9fba19
MD5 2536b41348126aab2a7cfc714bc47338
BLAKE2b-256 6bb28ec568d8df4139a09a969d59397c534c4d1fd8dd8fb482ebd89ae3d8feee

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