Intuitive CLI framework using argparse, rich, and pydantic
Project description
Treeparse
Tree-shaped Python CLI framework with built-in JSON introspection.
Most CLI frameworks focus on execution. Treeparse treats your CLI as both an executable interface and a structured data model — making it ideal for LLM tool schemas, automation workflows, and complex nested command hierarchies.
Why Treeparse
| Feature | argparse | Click | Typer | Treeparse |
|---|---|---|---|---|
| Tree-structured help | No | Partial | Partial | Yes |
| JSON CLI export | No | No | No | Yes |
| Explicit structural model | No | No | No | Yes |
| Signature validation | Minimal | No | Partial | Yes |
Quickstart
pip install treeparse
from treeparse import cli, command, argument
def greet(name: str):
print(f"Hello {name}")
greet_cmd = command(
name="greet",
callback=greet,
arguments=[argument(name="name", arg_type=str)],
)
app = cli(name="demo", commands=[greet_cmd])
if __name__ == "__main__":
app.run()
$ python app.py greet Alice
Hello Alice
$ python app.py --help
demo
└── greet
└── <NAME>
$ python app.py --json
{"name": "demo", "commands": [{"name": "greet", "arguments": [{"name": "name", "type": "str"}]}]}
Workflow
1. Build tool 1
# ink.py
ink = cli(name="ink", help="Annotate figures with Inkscape.")
ink.commands.append(command(
name="new", help="Open a new blank SVG.", callback=new,
arguments=[argument(name="name", arg_type=str)],
options=[option(flags=["--notes-dir", "-d"], arg_type=str, default="notes/draw")],
))
2. Build tool 2
# mind.py
mind = cli(name="mind", help="Build mind maps in Minder.")
mind.commands.append(command(
name="create", help="Create a new mind map.", callback=create,
arguments=[argument(name="title", arg_type=str)],
))
3. Plug into a toolbox
# toolbox.py
from treeparse import cli
from ink import ink
from mind import mind
toolbox = cli(name="toolbox", help="Creative toolbox.", subgroups=[ink, mind])
if __name__ == "__main__":
toolbox.run()
4. Teach the LLM
toolbox --json > skill.md
Human-readable tree
toolbox --help
toolbox Creative toolbox.
├── ink Annotate figures with Inkscape.
│ └── new <NAME> Open a new blank SVG.
│ └── --notes-dir, -d Directory to save SVGs (default: notes/draw)
└── mind Build mind maps in Minder.
└── create <TITLE> Create a new mind map.
Built-in flags
| Flag | Output |
|---|---|
--help, -h |
Rich tree, branch-pruned per subcommand |
--json, -j |
Full CLI structure as JSON |
--version, -V |
Auto-detected from package metadata, or set with version= on cli |
Examples
The examples/ directory contains 19 executable demonstrations covering every Treeparse feature (themes, group-level arguments/options, chaining, nargs="*"| "+", boolean flags, validation errors, root options, JSON export, custom sort/fold, etc.). They are living documentation and the primary reference for users and LLMs.
They are not installed as part of the package. After pip install treeparse only the core library and the treeparse console script are available.
Recommended development workflow
# Clone and set up (once)
git clone https://github.com/wr1/treeparse.git
cd treeparse
uv sync --dev
# Run any example with an editable install (no need to touch PYTHONPATH)
uv run --with-editable . python examples/demo.py --help
uv run --with-editable . python examples/all_themes_demo.py --help
python examples/validation_error_demo.py --help # after the uv command above
The test suite (tests/test_examples.py and test_demo_execution.py) loads the examples via importlib.util.spec_from_file_location and will continue to pass without any changes to packaging.
Models
from treeparse import cli, command, group, argument, option
from treeparse.models.chain import chain
| Model | Purpose |
|---|---|
cli |
Root — reusable as a subgroup in another cli |
group |
Namespace with optional fold=True to collapse in help |
command |
Executable action with a callback |
chain |
Runs multiple commands in sequence |
argument |
Positional — <ARG> required, [ARG] optional (nargs="?"/"*") |
option |
Named flag, with optional inheritance to child commands |
More
- Folding:
group(fold=True)collapses togroup [...]— drill in withtoolbox ink --help - Inheritance:
option(inherit=True)propagates to all child commands - Validation: callback param names and types checked against CLI definition at startup
- YAML config:
cli(yml_config=Path("config.yml"))overrides defaults at runtime - Themes:
theme="github"/"monokai"/"mononeon"/"monochrome" - Testing:
CliRunnerfor pytest integration
When to Use
Use Treeparse if you need:
- Structured CLI composition
- Machine-readable CLI definitions (LLM agents, orchestration, docs pipelines)
- Complex nested command hierarchies
Avoid if you only need a simple single-script CLI.
License
MIT
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 treeparse-0.2.7.tar.gz.
File metadata
- Download URL: treeparse-0.2.7.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
453a78782f91f1c0c783c234520b19bbf04a7bcdceae57aa706b0f5eb2938e4a
|
|
| MD5 |
5d540169e26ea2a4f8c0ed8377ce8bea
|
|
| BLAKE2b-256 |
42993fb151bebc1bdf6c7428d8b05826175ff3c1a82b1d950a72fd87bd05a110
|
Provenance
The following attestation bundles were made for treeparse-0.2.7.tar.gz:
Publisher:
publish.yml on wr1/treeparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treeparse-0.2.7.tar.gz -
Subject digest:
453a78782f91f1c0c783c234520b19bbf04a7bcdceae57aa706b0f5eb2938e4a - Sigstore transparency entry: 1704012964
- Sigstore integration time:
-
Permalink:
wr1/treeparse@3498198c22024eafc871a3d7a3007ccc33d80024 -
Branch / Tag:
refs/tags/v0.2.7 - Owner: https://github.com/wr1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3498198c22024eafc871a3d7a3007ccc33d80024 -
Trigger Event:
release
-
Statement type:
File details
Details for the file treeparse-0.2.7-py3-none-any.whl.
File metadata
- Download URL: treeparse-0.2.7-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
978479c8c38cd43c61f9d78d0db0ba90009610caf07ebb364b97333c7d9b80a4
|
|
| MD5 |
2421ef9fc5d462687ed259b98c9e5123
|
|
| BLAKE2b-256 |
fa96a05603cbe4442094e3acf4e33fdc2d9392dd5ea4d388957ec193e5b08bb0
|
Provenance
The following attestation bundles were made for treeparse-0.2.7-py3-none-any.whl:
Publisher:
publish.yml on wr1/treeparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
treeparse-0.2.7-py3-none-any.whl -
Subject digest:
978479c8c38cd43c61f9d78d0db0ba90009610caf07ebb364b97333c7d9b80a4 - Sigstore transparency entry: 1704012994
- Sigstore integration time:
-
Permalink:
wr1/treeparse@3498198c22024eafc871a3d7a3007ccc33d80024 -
Branch / Tag:
refs/tags/v0.2.7 - Owner: https://github.com/wr1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3498198c22024eafc871a3d7a3007ccc33d80024 -
Trigger Event:
release
-
Statement type: