aiocli


Nameaiocli JSON
Version 1.10.0 PyPI version JSON
download
home_pageNone
SummarySimple and lightweight async console runner.
upload_time2024-09-26 09:06:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
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.9

## 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": null,
    "name": "aiocli",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "ticdenis <navarrodenis940503@outlook.com>",
    "keywords": "asyncio, async, aio, cli, console",
    "author": null,
    "author_email": "ticdenis <navarrodenis940503@outlook.com>, yasti4 <adria_4_@hotmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d2/40/099db8562d3ea531e25bbbad8c9c987e964580db20a99eff4442fc0d5f0a/aiocli-1.10.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.9\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.10.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": "218810c08ddb885d618d3ba50b83596ac2d1f43074386c242571ce2b8b2c1b4d",
                "md5": "90c54e9a979a40900ce942c2bd2c06db",
                "sha256": "a24aff0d12502117b570d5e7a5d64453b7d649670a90ab923b3ceaf3098c7c0e"
            },
            "downloads": -1,
            "filename": "aiocli-1.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "90c54e9a979a40900ce942c2bd2c06db",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 13876,
            "upload_time": "2024-09-26T09:06:52",
            "upload_time_iso_8601": "2024-09-26T09:06:52.803198Z",
            "url": "https://files.pythonhosted.org/packages/21/88/10c08ddb885d618d3ba50b83596ac2d1f43074386c242571ce2b8b2c1b4d/aiocli-1.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d240099db8562d3ea531e25bbbad8c9c987e964580db20a99eff4442fc0d5f0a",
                "md5": "994d4138f8f97b629ba1bddee011b6d3",
                "sha256": "a06031367e782f7ad26b1a9f3664cd93c691379ea1ed51810832bcb4357b04d9"
            },
            "downloads": -1,
            "filename": "aiocli-1.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "994d4138f8f97b629ba1bddee011b6d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 16098,
            "upload_time": "2024-09-26T09:06:54",
            "upload_time_iso_8601": "2024-09-26T09:06:54.180409Z",
            "url": "https://files.pythonhosted.org/packages/d2/40/099db8562d3ea531e25bbbad8c9c987e964580db20a99eff4442fc0d5f0a/aiocli-1.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 09:06:54",
    "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: 4.84057s