You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

clitree

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clitree

A library to draw tree structures like the CLI utility 'tree' does

0.1.0
pipPyPI
Maintainers
1

CliTree

PyPI version Python Version License: MIT CI/CD Ruff

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) or getattr(node, name))
    • A callable that returns a string
  • children: How to obtain the children of a node. Can be:
    • A string key (uses node.get(children) or getattr(node, children))
    • A callable that returns an iterable of nodes (including generators)
    • Returns None or empty iterable for leaf nodes

Node Structure

When using string keys for name and children, nodes are typically:

  • Dictionaries with a get method, 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 None
  • TypeError: Raised when children are not iterable

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.