Skip to main content

A lightweight tool to visualize the structure of nested Python dictionaries and lists as a tree.

Project description

Dictree (dictree-sprint)

PyPI version Python versions License: MIT

A lightweight Python utility to visualize the schema of nested dictionaries, lists, tuples, and sets in a tree-like structure. It helps developers quickly understand complex data structures without getting lost in the actual values.

中文文档 (Chinese Documentation)


🚀 Features

  • Structured Visualization: Emulates the Unix tree command style for nested objects.
  • Representative Sampling: Automatically identifies element types in lists/sets. If a container contains dictionaries or other nested structures, it extracts their schema as a representative sample.
  • Depth Control: Use the max_depth parameter to prevent infinite recursion or to handle massive objects.
  • Customizable Templates: Customize how list/container statistics are displayed.
  • Execution Flexibility: Supports both direct printing to the console and returning results as strings.

📦 Installation

pip install dictree-sprint

🛠️ Quick Start

1. Basic Usage

Visualize a complex nested dictionary:

from dictree import sprint

data = {
    "users": [
        {
            "id": 1,
            "profile": {
                "name": "Alice",
                "hobbies": ["coding", "reading"]
            }
        },
        {
            "id": 2,
            "profile": {
                "name": "Bob",
                "hobbies": ["gaming"]
            }
        }
    ],
    "status": "success",
    "meta": {"page": 1, "total": 100}
}

sprint(data)

Output:

├── users
│   └── [2]: dict
│       ├── id
│       └── profile
│           ├── name
│           └── hobbies
│               └── [2]: str
├── status
└── meta
    ├── page
    └── total

2. Limiting Depth

When dealing with very large objects, use the max_depth parameter:

sprint(data, max_depth=1)

Output:

├── users
│   └── … (depth limit)
├── status
└── meta
    └── … (depth limit)

3. Capture as String

If you need to save the output to logs or a file:

tree_output = sprint(data, return_string=True)
print(f"Captured Schema Tree:\n{tree_output}")

4. Custom List Templates

Change how lists are represented using list_repr_template. The default is "{count}: {repr}".

sprint(data, list_repr_template="[{count} elements of {repr}]")

Example Output:

├── users
│   └── [2 elements of dict]
...

💡 Why Dictree?

When working with JSON from web scrapers, large API responses, or complex config files, standard print() or pprint often produces thousands of lines of output. dictree hides the values and extracts only the keys and container types, allowing you to see the entire hierarchy and structure at a glance.


📄 License

MIT License

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

dictree_print-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

dictree_print-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file dictree_print-0.1.0.tar.gz.

File metadata

  • Download URL: dictree_print-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for dictree_print-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4509ba90addd2dd1563e17c02b9be8d2c0989391f8186c65c280a9c11302ffe
MD5 c477306715acd2fe6806d40d52a104f8
BLAKE2b-256 470e26752d62cdfd5533cea81e6d579ff89f8dd8d866c78e1825cba8ac3b8b4c

See more details on using hashes here.

File details

Details for the file dictree_print-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dictree_print-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for dictree_print-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aad6c847e61ce6ab2b72639a3437051667d29d3727e5187d97d51172703de9e4
MD5 d0d80284c152dd6e6a0de77eab02671e
BLAKE2b-256 2c4ff6b9f65e2afc38359895bae2206d34f4d3b3b5d663abf90bd17e866fc416

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