aiocli


Nameaiocli JSON
Version 1.9.0 PyPI version JSON
download
home_page
SummarySimple and lightweight async console runner.
upload_time2023-11-06 09:20:17
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords asyncio async aio cli console
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Async cli client/commander framework

[![PyPI version](https://badge.fury.io/py/aiocli.svg)](https://badge.fury.io/py/aiocli)
[![PyPIDownloads](https://static.pepy.tech/badge/aiocli)](https://pepy.tech/project/aiocli)
[![CI](https://github.com/aiopy/python-aiocli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aiopy/python-aiocli/actions/workflows/ci.yml)

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](https://pypi.org/project/aiocli/) to install aiocli.

```bash
pip install aiocli
```

## Documentation

- Visit [aiocli docs](https://aiopy.github.io/python-aiocli/).

## Usage

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

from aiocli.commander import run_app, Application, Depends, State

app = Application(state={
    'envs': {
        'LOGGER_NAME': str(getenv('LOGGER_NAME', 'example_app')),
        'LOGGER_LEVEL': str(getenv('LOGGER_LEVEL', 'INFO')),
    }
})

def _get_logger(state: State) -> Logger:
    logger = getLogger(state.get('envs')['LOGGER_NAME'])
    logger.setLevel(state.get('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.7

## 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](https://github.com/aiopy/python-aiocli/blob/master/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "aiocli",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "ticdenis <denisnavarroalcaide@outlook.es>",
    "keywords": "asyncio,async,aio,cli,console",
    "author": "",
    "author_email": "ticdenis <denisnavarroalcaide@outlook.es>, yasti4 <adria_4_@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/99/58/3442287318d77e8832ab078c87edb2ea26a3ed860fd17bea0e877bd64a9e/aiocli-1.9.0.tar.gz",
    "platform": null,
    "description": "# Async cli client/commander framework\n\n[![PyPI version](https://badge.fury.io/py/aiocli.svg)](https://badge.fury.io/py/aiocli)\n[![PyPIDownloads](https://static.pepy.tech/badge/aiocli)](https://pepy.tech/project/aiocli)\n[![CI](https://github.com/aiopy/python-aiocli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aiopy/python-aiocli/actions/workflows/ci.yml)\n\naiocli is a Python library for simple and lightweight async console runner.\n\nFull compatibility with argparse module and highly inspired by aiohttp module.\n\n## Installation\n\nUse the package manager [pip](https://pypi.org/project/aiocli/) to install aiocli.\n\n```bash\npip install aiocli\n```\n\n## Documentation\n\n- Visit [aiocli docs](https://aiopy.github.io/python-aiocli/).\n\n## Usage\n\n```python\nfrom logging import getLogger, Logger, StreamHandler\nfrom os import getenv\n\nfrom aiocli.commander import run_app, Application, Depends, State\n\napp = Application(state={\n    'envs': {\n        'LOGGER_NAME': str(getenv('LOGGER_NAME', 'example_app')),\n        'LOGGER_LEVEL': str(getenv('LOGGER_LEVEL', 'INFO')),\n    }\n})\n\ndef _get_logger(state: State) -> Logger:\n    logger = getLogger(state.get('envs')['LOGGER_NAME'])\n    logger.setLevel(state.get('envs')['LOGGER_LEVEL'])\n    handler = StreamHandler()\n    logger.addHandler(handler)\n    return logger\n\n@app.command(name='greet:to', positionals=[('name', {'default': 'World!'})])\nasync def handle_greeting(name: str, logger: Logger = Depends(_get_logger)) -> int:\n    logger.info(f'Hello {name}')\n    return 0\n\n@app.command(name='div', optionals=[('--a', {'type': float}), ('--b', {'type': float})])\nasync def handle_division(a: float, b: float, logger: Logger = Depends(_get_logger)) -> int:\n    try:\n        logger.info(f'Result {a} / {b} = {(a / b)}')\n        return 0\n    except BaseException as err:\n        logger.error(f'Error: {err}')\n        return 1\n\n# python3 main.py <command> <positionals> <optionals>\nif __name__ == '__main__':\n    run_app(app)\n```\n\n## Requirements\n\n- Python >= 3.7\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://github.com/aiopy/python-aiocli/blob/master/LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple and lightweight async console runner.",
    "version": "1.9.0",
    "project_urls": {
        "documentation": "https://aiopy.github.io/python-aiocli/",
        "repository": "https://github.com/aiopy/python-aiocli"
    },
    "split_keywords": [
        "asyncio",
        "async",
        "aio",
        "cli",
        "console"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0fb5b1e982024b7189cd537445b369800a5bd455f7983b2f0d9dadde96d0460",
                "md5": "cc77b125182bd2982603722f55328048",
                "sha256": "d268a8aa7db722bbccc3289f4c7265685c2cc1ef6986af3ab7bb2307fd51bc0f"
            },
            "downloads": -1,
            "filename": "aiocli-1.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cc77b125182bd2982603722f55328048",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13840,
            "upload_time": "2023-11-06T09:20:15",
            "upload_time_iso_8601": "2023-11-06T09:20:15.750500Z",
            "url": "https://files.pythonhosted.org/packages/b0/fb/5b1e982024b7189cd537445b369800a5bd455f7983b2f0d9dadde96d0460/aiocli-1.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99583442287318d77e8832ab078c87edb2ea26a3ed860fd17bea0e877bd64a9e",
                "md5": "7fdf772b259ee93f7a10d45c73a2583d",
                "sha256": "6f8c37490e81322bfe3cc9b0a06fc87051d90e463f3de192d51de94d88665422"
            },
            "downloads": -1,
            "filename": "aiocli-1.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7fdf772b259ee93f7a10d45c73a2583d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15390,
            "upload_time": "2023-11-06T09:20:17",
            "upload_time_iso_8601": "2023-11-06T09:20:17.575357Z",
            "url": "https://files.pythonhosted.org/packages/99/58/3442287318d77e8832ab078c87edb2ea26a3ed860fd17bea0e877bd64a9e/aiocli-1.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-06 09:20:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aiopy",
    "github_project": "python-aiocli",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiocli"
}
        
Elapsed time: 0.14439s