Skip to main content

A Python package for managing and visualizing interval tree structures

Project description

Tree Interval Logo

Tree Interval

A powerful Python package for managing, analyzing, and visualizing tree structures with rich interval-based node positioning

Try it on Replit

✨ Features

  • 🔮 Future Class: Powerful dynamic attribute handling with context-aware error reporting and smart chain creation
  • 📍 Position-Aware Nodes: Track code positions with line numbers, column offsets and intervals
  • 🌲 AST Analysis: Built-in support for Python AST traversal and node location
  • 🔍 Frame Analysis: Runtime code inspection with frame position tracking
  • 🎨 Rich Visualization: Multiple visualization options including ASCII trees and Rich-based pretty printing
  • 💾 JSON Serialization: Full support for saving and loading tree structures
  • 🔎 Flexible Node Search: Parent, child and sibling search with custom predicates

🚀 Quick Start

Dynamic Attribute Handling with Future

from tree_interval import Future

class Nested:
    def __init__(self):
        self.__dict__ = {}
        
    def __getattr__(self, name):
        return Future(name, frame=1, instance=self)

# Dynamic attribute chain creation
obj = Nested()
obj.a.b.c = 42  # Creates nested structure automatically
print(obj.a.b.c)  # 42

# Smart error reporting
print(obj.x.y.z)  # Raises detailed error with context

Tree Operations

from tree_interval import Tree, Leaf, Position

# Create a basic tree
tree = Tree("Example")
root = Leaf(Position(0, 100), "Root")
child = Leaf(Position(10, 50), "Child")

tree.root = root
tree.add_leaf(child)

# Visualize the tree
tree.visualize()

📦 Installation

pip install tree-interval

🎯 Core Components

Position Types

# Basic Position
pos = Position(0, 100)

# Line-Aware Position
pos = Position(0, 100)
pos.lineno = 1
pos.end_lineno = 5

# Column-Aware Position
pos = Position(0, 100)
pos.col_offset = 4
pos.end_col_offset = 8

Tree Visualization

# Basic ASCII Tree
tree.visualize()

# Rich Pretty Printing
from tree_interval.rich_printer import RichTreePrinter
printer = RichTreePrinter()
printer.print_tree(tree)

📚 Documentation

💡 Use Cases

  1. Code Analysis

    • Track source positions in AST nodes
    • Locate runtime code execution points
    • Analyze code structure and relationships
  2. Tree Visualization

    • Debug tree structures
    • Generate documentation
    • Analyze hierarchical data
  3. Position Tracking

    • Map source locations
    • Track text positions
    • Handle nested intervals

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by Kairos

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

tree_interval-0.1.33.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

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

tree_interval-0.1.33-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file tree_interval-0.1.33.tar.gz.

File metadata

  • Download URL: tree_interval-0.1.33.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for tree_interval-0.1.33.tar.gz
Algorithm Hash digest
SHA256 d84a8f52b66c7dc6355667135238cc0ae4343c88c73976914b1a1bcafff4b8bb
MD5 dab18aa96a001708a89cf91778178cac
BLAKE2b-256 4c485f8ba241a9bdb9685b24d0c2ccbf2b248184ac9189eb7f821aa9a7a9aa94

See more details on using hashes here.

File details

Details for the file tree_interval-0.1.33-py3-none-any.whl.

File metadata

  • Download URL: tree_interval-0.1.33-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for tree_interval-0.1.33-py3-none-any.whl
Algorithm Hash digest
SHA256 0661694841aca12a8513e197c8fe0962c964d906afe905af522ce65a0e4747c3
MD5 c7805dbd5f3c3d9d135c7e9864c743d7
BLAKE2b-256 a4119b1db8822465d6a7df1177c453ee36798681de085cd680a2bcd6698d4be1

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