Skip to main content

asynccli

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

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

License

MIT

Authors

asynccli was written by Adam Hopkins.

Metadata

Release files for asynccli 0.1.1

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

Source distribution (sdist)

Source distribution for asynccli 0.1.1
File Size Uploaded
asynccli-0.1.1.tar.gz 4.4 kB Details

Release files / asynccli-0.1.1.tar.gz

Download URL asynccli-0.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
307531c0b435fe3d2d2bed16ea4e4f4065e8f329e175c69687b1005728b75e20
BLAKE2b-256 checksum
How to use checksums
488007fb57ba54786f8ae1b83c8254e9054ddc2fb4593a74ebd5007fe6e4e622
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.3

1 release file

0.1.2

1 release file

This release

0.1.1 This release

1 release file

0.1.0

1 release file

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