Skip to main content

decree-tree

So you need to create a command-line interface. Perhaps you are familiar with argparse but would like to define subcommands using classes? Then decree-tree can help with that!

The decree-tree package provides a lightweight means for defining nested command-line interfaces, using standard argparse-based parsing wrapped in a flexible class.

Installation

To install decree-tree from PyPI via pip, run this shell command with the proper Python environment active:

pip install decree-tree

If you are using a different package manager, such as Poetry, use its appropriate installation command for the decree-tree package on PyPI.

Usage

To create a command tree, subclass decree_tree.DecreeTree create new commands, then assemble their instances appropriately. For example, consider this file command.py:

from decree_tree import DecreeTree

class Root(DecreeTree):
    def add_arguments(self, parser):
        super().add_arguments(parser)
        parser.add_argument('-v', '--value')

class Echo(DecreeTree):
    def execute(self):
        super().execute()
        print(self.options.value)

class Double(DecreeTree):
    def execute(self):
        super().execute()
        print(self.options.value, self.options.value)

root = Root()
root.add(Echo)
root.add(Double)

if __name__ == '__main__':
    root.run()

Invoking script above yields results like the following:

$ python command.py double -v bark
bark bark

This script can be called in many other ways, including displaying autogenerated help. The behavior is very customizable.

Documentation

See the full documentation here.

Status

This package is relatively stable, and has had an initial release, but is still under initial development.

To contribute, create an issue or submit an MR!

Release files for decree-tree 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decree-tree 0.4.0
File Size Uploaded
decree_tree-0.4.0.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for decree-tree 0.4.0
File Interpreter ABI Platform
decree_tree-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.2 kB

Release files / decree_tree-0.4.0.tar.gz

Download URL decree_tree-0.4.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ac20d4d889549f7e3ac693b594dde4866efe08b9a59140d05aa3b6b9603411c4
BLAKE2b-256 checksum
How to use checksums
fd8b6934a6687576f7a8fb7a2f3fc38efb86dfbe7ab1a37549b6bd9c0a8edf63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / decree_tree-0.4.0-py3-none-any.whl

Download URL decree_tree-0.4.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70cac1fc47f8a52f0eb455a10c24161603dbbd898c59ad7b4ffc4eea47a89b50
BLAKE2b-256 checksum
How to use checksums
ff74101ff1d0c376733df99c90bbe3616d790e67ed9838fe9f41671c0d315895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page