Skip to main content

arbol -- Arborescent Printouts in Python

Project description

arbol | Arborescent Printouts in Python

s

Do you have a script, a command line tool, or some workflow in Python that has lots of print statements, and you can't make sense of it once it adds up to hundreds of lines on the console? Sounds familiar?

arbol organizes your stdout prints in a hierarchy that follows the structure of your code. Use a simple context manager to define the hierarchy and aprint instead of print, and voila. When the optional dependencies are installed, the output is colored with an exquisitely crafted combination of colors, making it even more visually appealing.

If you are wondering, arbol means tree in Spanish.

Why not use traditional Python logging? We made the choice of sticking to a plain and simple scheme that matches the usage of print statements.

Features

  • aprint: Drop-in replacement for the built-in print function
  • asection: Context manager to create tree nodes with automatic timing
  • section: Decorator to wrap functions in a section
  • acapture: Context manager to capture stdout/stderr from third-party code
  • Configuration: Control depth, colors, timing display via Arbol class

Installation

Install with pip:

pip install arbol

Or with optional color support:

pip install arbol[colors]

Optional Dependencies

For colors, install the ansicolors package:

pip install ansicolors

For color support on all operating systems (particularly Windows), install colorama:

pip install colorama

Note: both are optional — arbol works fine without them.

Example

from arbol import Arbol, aprint, section, asection, acapture

# Limit the tree depth:
Arbol.max_depth = 4

# Use aprint instead of print
aprint('Test')

# Decorate functions to wrap them in a section:
@section('function')
def fun(x):
    if x >= 0:
        with asection('recursive call'):
            aprint(f"f(x)+1={fun(x - 1)}")

# Context manager lets you go down one level in the tree:
with asection('a section'):
    aprint('a line')
    aprint('another line')
    aprint('we are done \n or are we? \n someone gotta check!')

    with asection('a subsection'):
        aprint('another line')
        aprint('we are done')

    # Works through function calls:
    fun(2)

    # Capture stdout from third-party code (experimental):
    with acapture():
        print("This gets captured")

    # Disable elapsed time display:
    Arbol.elapsed_time = False
    fun(100)

aprint('demo is finished...')

# Turn off all output:
Arbol.enable_output = False
aprint('you will not see this')

Output:

example

Configuration

All settings are class attributes on Arbol:

Attribute Default Description
enable_output True Set to False to suppress all output
elapsed_time True Set to False to hide timing information
max_depth math.inf Maximum tree depth (deeper sections show truncation)
colorful True Set to False to disable colors
passthrough False Set to True to bypass tree formatting entirely

Color attributes (c_text, c_scaffold, c_timing, c_section, c_truncation) can also be customized with hex color codes.

Roadmap

Ideas we might consider, from serious to speculative:

  • More color styles to choose from
  • Intercept stdout from C code so that printouts from native libraries are formatted too (unclear if possible)
  • Generate tree automatically by inspecting stack
  • Interoperability with the logging package
  • Better multi-thread/process support — currently printouts get interleaved. One idea: capture outputs per-thread and display them in order when done.

Development

make install    # Install hatch and set up environment
make test       # Run tests
make demo       # Run the demo
make lint       # Run linter (ruff)
make format     # Format code (ruff)
make check      # Run all checks (lint + format)
make publish    # Bump version and release

Contributions

Pull requests welcome!

Authors

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

arbol-2026.2.22.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

arbol-2026.2.22-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file arbol-2026.2.22.tar.gz.

File metadata

  • Download URL: arbol-2026.2.22.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for arbol-2026.2.22.tar.gz
Algorithm Hash digest
SHA256 6ec531f8f3b06283da0471d4e351ff195f79709d5ab2d71a59c4275b29219d43
MD5 5586227d571f9f60bfabbf93b1e3e1ff
BLAKE2b-256 364ff4a19090168b83c67423129d034f4d0075affc193e93fed8fb2a282cc959

See more details on using hashes here.

Provenance

The following attestation bundles were made for arbol-2026.2.22.tar.gz:

Publisher: publish.yml on royerlab/arbol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arbol-2026.2.22-py3-none-any.whl.

File metadata

  • Download URL: arbol-2026.2.22-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for arbol-2026.2.22-py3-none-any.whl
Algorithm Hash digest
SHA256 c3f8f7b226b4ff8fcc7484011dbbcd096f416be7a0f00be3828893e49beb35b8
MD5 b2b9f640cef7ce8cf549a09b1527282b
BLAKE2b-256 8ce0162aed5d9e990c0d49286def7d9e5163536667ddb881292efe9ee3237f2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for arbol-2026.2.22-py3-none-any.whl:

Publisher: publish.yml on royerlab/arbol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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