Skip to main content

A CLI framework based on asyncio

Project description

Latest PyPI version Version status Python 3.5 and 3.6 Latest Travis CI build status Codacy grade Codacy coverage

A CLI framework based on asyncio.

Usage

The simplest usage is to just pass in an async function.

import asynccli


async def mycli():
    print("Hello, world.")


if __name__ == '__main__':
    app = asynccli.App(mycli)
    app.run()

It can also be instantiated as a class, as long it has a call method.

import asynccli


class DivisionCalculator(asynccli.CLI):
    numerator = asynccli.Integer(help_text='This is the numerator.')
    denominator = asynccli.Integer()

    async def call(self):
        print(self.first_num / self.second_num)


if __name__ == '__main__':
    app = asynccli.App(DivisionCalculator)
    app.run()

In the DivisionCalculator example above, you would call your script like this:

$ /path/to/script.py 2 3
0.6666666666666666

What if you want to have a tiered CLI with a hierarchy of commands? First, create your command by subclassing CLI as above. Then, wrap the whole thing inside of the TieredCLI class, and pass that to the App.

class Calculator(asynccli.TieredCLI):
    d = DivisionCalculator

Now, to invoke the script, you have an extra argument to call:

$ /path/to/script.py d 2 3
0.6666666666666666

Installation

pip install asynccli

Requirements

Currently it requires Python 3.5 to make use of async/await. It uses argparse under the hood, and therefore has no dependencies outside of the standard library.

Roadmap

  • Additional Argument types

  • Integration of additional argparse features

  • Add uvloop

  • Better support for help documentation

Testing

You can invoke the test scripts a few different ways:

$ py.test
$ python setup.py test
$ python -m py.test

And, in order to generate the test coverage:

$ coverage run -m py.test

License

MIT

Authors

asynccli was written by Adam Hopkins.

Project details


Download files

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

Source Distribution

asynccli-0.1.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file asynccli-0.1.3.tar.gz.

File metadata

  • Download URL: asynccli-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asynccli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c3603f80856d8982817f0f2fcbe0429975242078e1bbae3e96cd4917f20c4c2a
MD5 c8fdce172beb05474d7ef22fb0e1dcd6
BLAKE2b-256 57f8c4a2cef122af5a6eafc6d468346e1625b07713ea7ee8ab90caa27d47bc96

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page