Skip to main content

uroboros

Build Status PyPI pyversions PyPI version shields.io GitHub license

Simple framework for building scalable CLI tool.

NOTE
This framework currently under development. Please be careful to use.

Features

  • Simple interface
  • Pure python
    • Thin wrapper of argparse
    • No third party dependencies
  • Easy to reuse common options
  • Easy to create sub commands
    • Nested sub command is also supported

Environment

  • Python >= 3.5
    • No support for python 2.x

Install uroboros

$ pip install uroboros

How to use

Implement your command using uroboros.Command and create a command tree.

# sample.py
from uroboros import Command
from uroboros.constants import ExitStatus

class RootCommand(Command):
    """Root command of your application"""
    name = 'sample'
    long_description = 'This is a sample command using uroboros'

    def build_option(self, parser):
        """Add optional arguments"""
        parser.add_argument('--version', action='store_true', default=False, help='Print version')
        return parser

    def run(self, args):
        """Your own script to run"""
        if args.version:
            print("{name} v{version}".format(
                name=self.name, version='1.0.0'))
        else:
            self.print_help()
        return ExitStatus.SUCCESS

class HelloCommand(Command):
    """Sub command of root"""
    name = 'hello'
    short_description = 'Hello world!'
    long_description = 'Print "Hello world!" to stdout'

    def run(self, args):
        print(self.short_description)
        return ExitStatus.SUCCESS

# Create command tree
root_cmd = RootCommand()
root_cmd.add_command(HelloCommand())

if __name__ == '__main__':
    exit(root_cmd.execute())

Then, your command works completely.

$ python sample.py -h
usage: sample [-h] [--version] {hello} ...

This is a sample command using uroboros

optional arguments:
  -h, --help  show this help message and exit
  --version   Print version

Sub commands:
  {hello}
    hello     Hello world!
$ python sample.py --version
sample v1.0.0
$ python sample.py hello
Hello world!

If you want to use new sub command sample.py hello xxxx, you just implement new XXXXCommand and add it to Hello.

root_cmd = RootCommand().add_command(
    HelloCommand().add_command(
        XXXXCommand()
    )
)

You can see other examples in examples.

Develop

First, clone this repository and install uroboros with editable option.

$ git clone https://github.com/pddg/uroboros
$ cd /path/to/uroboros
$ pip install -e .

Use Pipenv for lint and test.

# Create environment
$ pipenv install --dev
# Execute lint by flake8
$ pipenv run lint
# Execute test by py.test
$ pipenv run test

Also support test with tox. Before execute test with tox, you should make available to use python 3.5 and 3.6, 3.7.

License

Apache 2.0

Author

Shoma Kokuryo

Metadata

Release files for uroboros 0.2.4

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

Source distribution (sdist)

Source distribution for uroboros 0.2.4
File Size Uploaded
uroboros-0.2.4.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uroboros 0.2.4
File Interpreter ABI Platform
uroboros-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / uroboros-0.2.4.tar.gz

Download URL uroboros-0.2.4.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f57343ef0c72d114564746edc4cf337cbd30f5407da09b1eba1951d87a819594
BLAKE2b-256 checksum
How to use checksums
10fe372131d52e37e8a5b6ca011d778723079b4055a7dfe4a5cb966c9db133cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

Release files / uroboros-0.2.4-py3-none-any.whl

Download URL uroboros-0.2.4-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f47d0e8eeafdb9d128b6e408c546a61fe34e688b7f915f79cc14a1f593626950
BLAKE2b-256 checksum
How to use checksums
244f097ac1ca9b4c1d1085a95d3044b28a1401749d736e8bb2c9235a59b5052a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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