Skip to main content

nest-tree

A Python tool to visualize the structure of nested dictionaries and lists in a tree-like format, similar to the Unix tree command.

Installation

pip install nest-tree

Usage

Tl;dr

from nest_tree import tree

tree(data)

tree(data, leaf="none", level=None, print_output=True, return_output=False)

  • Parameters:
    • data (dict | list): The nested dictionary or list to visualize.
    • leaf (str): Controls leaf display - "none" (default), "value", or "type".
    • level (int | None): Maximum depth. If None, expand fully.
    • print_output (bool): If True, print to stdout. Default: True.
    • return_output (bool): If True, return what would be printed as a string. Default: False (in order to avoid busy output in interactive REPLs like IPython).
  • Return:
    • If return_output is True: the output is returned as a string. No return value otherwise.

Example

Consider the following nested list/dict

data = {
    "fruits": ["apple", "banana"],
    "vegetables": {
        "green": ["lettuce", "spinach"],
        "root": ["carrot", "potato"],
    },
    "requirement": [
        {"type": "protein", "amount": 100, "unit": "g"},
        {"type": "vitamin C", "amount": 80, "unit": "mg"}
    ]
}

tree(data, level=2)

├── fruits
│   ├── [0]
│   └── [1]
├── vegetables
│   ├── green
│   └── root
└── requirement
    ├── [0]
    └── [1]

tree(data, leaf="type")

├── fruits
│   ├── [0]
│   │   └── <class 'str'>
│   └── [1]
│       └── <class 'str'>
├── vegetables
│   ├── green
│   │   ├── [0]
│   │   │   └── <class 'str'>
│   │   └── [1]
│   │       └── <class 'str'>
│   └── root
│       ├── [0]
│       │   └── <class 'str'>
│       └── [1]
│           └── <class 'str'>
└── requirement
    ├── [0]
    │   ├── type
    │   │   └── <class 'str'>
    │   ├── amount
    │   │   └── <class 'int'>
    │   └── unit
    │       └── <class 'str'>
    └── [1]
        ├── type
        │   └── <class 'str'>
        ├── amount
        │   └── <class 'int'>
        └── unit
            └── <class 'str'>

tree(data, leaf="value")

├── fruits
│   ├── [0]
│   │   └── apple
│   └── [1]
│       └── banana
├── vegetables
│   ├── green
│   │   ├── [0]
│   │   │   └── lettuce
│   │   └── [1]
│   │       └── spinach
│   └── root
│       ├── [0]
│       │   └── carrot
│       └── [1]
│           └── potato
└── requirement
    ├── [0]
    │   ├── type
    │   │   └── protein
    │   ├── amount
    │   │   └── 100
    │   └── unit
    │       └── g
    └── [1]
        ├── type
        │   └── vitamin C
        ├── amount
        │   └── 80
        └── unit
            └── mg

Running Tests

python -m unittest tests.test_tree -v

Metadata

Release files for nest-tree 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nest-tree 0.1.1
File Size Uploaded Provenance
nest_tree-0.1.1.tar.gz 5.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nest-tree 0.1.1
File Interpreter ABI Platform
nest_tree-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / nest_tree-0.1.1.tar.gz

Download URL nest_tree-0.1.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
868df5a631a00be4a81ed3092efc3ff74a5f360effd0d92685ca5975649d5df3
BLAKE2b-256 checksum
How to use checksums
95d5dd1f8326bb3de6452503942556d27e12fde1c04eca8ca82537613d43cce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / nest_tree-0.1.1-py3-none-any.whl

Download URL nest_tree-0.1.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
442aeb326b4fa34b75c66821aa97a0a839dcc0d545408061c4010121ed4b2941
BLAKE2b-256 checksum
How to use checksums
8bf0351f7942ef19e5f5df13200ec97ddc653c4c9af04711fe3cee7e895af714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for nest-tree 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page