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!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decree_tree-0.4.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

decree_tree-0.4.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file decree_tree-0.4.0.tar.gz.

File metadata

  • Download URL: decree_tree-0.4.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for decree_tree-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ac20d4d889549f7e3ac693b594dde4866efe08b9a59140d05aa3b6b9603411c4
MD5 cb474c2c5baccaf2337e9bfb33fc864d
BLAKE2b-256 fd8b6934a6687576f7a8fb7a2f3fc38efb86dfbe7ab1a37549b6bd9c0a8edf63

See more details on using hashes here.

File details

Details for the file decree_tree-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: decree_tree-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for decree_tree-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70cac1fc47f8a52f0eb455a10c24161603dbbd898c59ad7b4ffc4eea47a89b50
MD5 73500680c047265d0218e28746ee07ea
BLAKE2b-256 ff74101ff1d0c376733df99c90bbe3616d790e67ed9838fe9f41671c0d315895

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page