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

Usage

# examples/commander.py
from functools import lru_cache
from logging import getLogger, Logger, StreamHandler, Formatter
from os import getenv
from typing import Dict, Any

from aiocli import commander

app = commander.Application()

@lru_cache
def _get_envs() -> Dict[str, Any]:
    return {
        'LOGGER_NAME': getenv('LOGGER_NAME', 'example_commander'),
        'LOGGER_LEVEL': getenv('LOGGER_LEVEL', 'INFO'),
        'LOGGER_FORMAT': getenv('LOGGER_FORMAT', '[%(asctime)s] - %(name)s - %(levelname)s - %(message)s')
    }

def _get_logger(envs: Dict[str, Any] = commander.Depends(_get_envs)) -> Logger:
    logger = getLogger(envs['LOGGER_NAME'])
    logger.setLevel(envs['LOGGER_LEVEL'])
    handler = StreamHandler()
    handler.setLevel(envs['LOGGER_LEVEL'])
    formatter = Formatter(envs['LOGGER_FORMAT'])
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger

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

# python3 commander.py <command> <positionals> <optionals>
if __name__ == '__main__':
    commander.run_app(app, argv=['greet:to', '--name', 'GitHub!'])

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.0.tar.gz (9.6 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.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiocli-1.4.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12

File hashes

Hashes for aiocli-1.4.0.tar.gz
Algorithm Hash digest
SHA256 fd36efc989267cd9df6e20a38b114ea66ffbcee1a077d104f63f5420ea3a2e29
MD5 044b1d788028958a95b16f4d258ab562
BLAKE2b-256 7b908d9f5f8c85392be639c4e8f5e5769599d1617a7a4c56e5a6fecfbce3286c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiocli-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12

File hashes

Hashes for aiocli-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fe70312d0f90e755834444bef552ad1557b8ba79c90b283cf2a864a19aaac0f
MD5 699d3c8e60abffa158de1e4278356f73
BLAKE2b-256 23e98f992c6ed6cb1e52e1a58cc2624ca814980265ea8bfd3227852538c0d8d2

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