Skip to main content

Simple and lightweight async console runner.

Project description

Async cli client/commander framework

aiocli is a Python library for simple and lightweight async console runner.

Full compatibility with argparse module and highly inspired by aiohttp module.

Installation

Use the package manager pip to install aiocli.

pip install aiocli

Documentation

Usage

from logging import getLogger, Logger, StreamHandler
from os import getenv

from aiocli.commander import run_app, Application, Depends

app = Application()

def _get_envs() -> dict[str, str]:
    return {
        'LOGGER_NAME': str(getenv('LOGGER_NAME', 'example_app')),
        'LOGGER_LEVEL': str(getenv('LOGGER_LEVEL', 'INFO')),
    }

def _get_logger(envs: dict[str, str] = Depends(_get_envs)) -> Logger:
    logger = getLogger(envs['LOGGER_NAME'])
    logger.setLevel(envs['LOGGER_LEVEL'])
    handler = StreamHandler()
    logger.addHandler(handler)
    return logger

@app.command(name='greet:to', positionals=[('--name', {'default': 'World!'})])
async def handle_greeting(name: str, logger: Logger = Depends(_get_logger)) -> int:
    logger.info(f'Hello {name}')
    return 0

@app.command(name='div', optionals=[('--a', {'type': float}), ('--b', {'type': float})])
async def handle_division(a: float, b: float, logger: Logger = Depends(_get_logger)) -> int:
    try:
        logger.info(f'Result {a} / {b} = {(a / b)}')
        return 0
    except BaseException as err:
        logger.error(f'Error: {err}')
        return 1

# python3 main.py <command> <positionals> <optionals>
if __name__ == '__main__':
    run_app(app)

Requirements

  • Python >= 3.6

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

aiocli-1.4.8.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

aiocli-1.4.8-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file aiocli-1.4.8.tar.gz.

File metadata

  • Download URL: aiocli-1.4.8.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for aiocli-1.4.8.tar.gz
Algorithm Hash digest
SHA256 1746bdb961be41067d69dd8c5681194e4b250ed137998441035c3d411a093ca7
MD5 440144cb1af8b173be31d58e2199a787
BLAKE2b-256 eadfedf7a355c59b89647efbd7e14f30f6e4ef89d815930ea94558ed66044e75

See more details on using hashes here.

File details

Details for the file aiocli-1.4.8-py3-none-any.whl.

File metadata

  • Download URL: aiocli-1.4.8-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

File hashes

Hashes for aiocli-1.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 abad1b4c469eef00a474b34d1b6a246ff50dab5333298ff3668ff19a5e4fa55d
MD5 6fec076684d20aa5a684659f9a7a1a9f
BLAKE2b-256 9f621edaed79e09ee280a96e02c672d4a99aa70528270b811fc7ff38aabdbe35

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 Pingdom Monitoring Sentry Error logging StatusPage Status page