A lightweight tool to visualize the structure of nested Python dictionaries and lists as a tree.
Project description
Dictree (dictree-sprint)
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.
🚀 Features
- Structured Visualization: Emulates the Unix
treecommand 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_depthparameter 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4509ba90addd2dd1563e17c02b9be8d2c0989391f8186c65c280a9c11302ffe
|
|
| MD5 |
c477306715acd2fe6806d40d52a104f8
|
|
| BLAKE2b-256 |
470e26752d62cdfd5533cea81e6d579ff89f8dd8d866c78e1825cba8ac3b8b4c
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad6c847e61ce6ab2b72639a3437051667d29d3727e5187d97d51172703de9e4
|
|
| MD5 |
d0d80284c152dd6e6a0de77eab02671e
|
|
| BLAKE2b-256 |
2c4ff6b9f65e2afc38359895bae2206d34f4d3b3b5d663abf90bd17e866fc416
|