A library to draw tree structures like the CLI utility 'tree' does
Project description
CliTree
clitree is a library to draw tree structures like the CLI utility tree does.
Install it with:
pip install clitree
Example usage:
>>> from clitree import tree
>>>
>>> data = {
... "name": "root",
... "children": [
... {"name": "docs", "children": [
... {"name": "api.md", "children": []},
... {"name": "guide.md", "children": []}
... ]},
... {"name": "src", "children": [
... {"name": "main.py", "children": []},
... {"name": "utils", "children": [
... {"name": "helpers.py", "children": []},
... {"name": "config.py", "children": []}
... ]}
... ]},
... {"name": "tests", "children": []}
... ]
... }
>>>
>>> print(tree(data))
root
├── docs
│ ├── api.md
│ └── guide.md
├── src
│ ├── main.py
│ └── utils
│ ├── helpers.py
│ └── config.py
└── tests
Parameters
name: How to extract the name of a node. Can be:- A string key (uses
node.get(name)orgetattr(node, name)) - A callable that returns a string
- A string key (uses
children: How to obtain the children of a node. Can be:- A string key (uses
node.get(children)orgetattr(node, children)) - A callable that returns an iterable of nodes (including generators)
- Returns
Noneor empty iterable for leaf nodes
- A string key (uses
Node Structure
When using string keys for name and children, nodes are typically:
- Dictionaries with a
getmethod, or - Objects with attributes accessible via
getattr
However, since name and children can be callables, nodes can be of any type, as the callables are responsible for extracting the required information.
Requirements:
- The name must resolve to a string value
- Children must be iterable or None
Error Handling
ValueError: Raised when a node's name resolves to NoneTypeError: Raised when children are not iterable
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 clitree-0.1.0.tar.gz.
File metadata
- Download URL: clitree-0.1.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9174bcb71bd18e2601770903dcae89753b271cc425424ae3b124815b86d4dff6
|
|
| MD5 |
e5d302d8f611dfd37bb979f13800782b
|
|
| BLAKE2b-256 |
b8901cda0dd9ce23cffcaab78abf1c260a42af1a91c1bfdd253e19ce0d5b9991
|
File details
Details for the file clitree-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clitree-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62bda59ffe29e81effd22f6765a999eda6289592709db73d9c9e6596017c91d
|
|
| MD5 |
50d9a57eacaf9d5db2353021dec2234c
|
|
| BLAKE2b-256 |
d3152fcd3573014aa5124d7c7a149b365a3cb6d74e0b917641abb6f2d7f33b49
|