Simple and lightweight async console runner.
Project description
Async Python application
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
from asyncio import get_event_loop, AbstractEventLoop
from pyaioapp import AsyncApplication
from aiocli.commander import Application, run_app, Command
from typing import Dict as Container, Any
SETTINGS = {
'DEBUG': '0', 'DEBUG_HOST': '0.0.0.0', 'DEBUG_PORT': '5678'
}
async def get_container(settings: dict, **kwargs) -> Container:
async def hello_world_command(args: dict) -> int:
print(f'Hello {args.get("name")}!')
return 0
return {
'hello_world_command': hello_world_command
}
async def get_runner(container: Container) -> Application:
return Application([
Command(
name='hello:world',
handler=container.get('hello_world_command'),
optionals=[('--name', {'default': 'World'})],
positionals=[]
),
])
class CliApp(AsyncApplication[Container, Application]):
async def __aenter__(self) -> Application:
self._container = await get_container(SETTINGS, loop=self.loop)
self._runner = await get_runner(self._container)
return self._runner
def __call__(self) -> None:
run_app(app=self.__aenter__(), loop=self.loop)
def main(loop: AbstractEventLoop) -> Any:
if SETTINGS['DEBUG'] == '1':
from ptvsd import enable_attach # type: ignore
enable_attach(
address=(SETTINGS['DEBUG_HOST'], int(SETTINGS['DEBUG_PORT']))
)
return CliApp(loop).__call__()
if __name__ == '__main__':
main(get_event_loop())
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiocli-1.0.0.tar.gz.
File metadata
- Download URL: aiocli-1.0.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/5.3.0-1032-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f49f97e7767f36bc12cd2a3a0c29681c9ec32bc3bc31e8de6b6e03fcc45753ba
|
|
| MD5 |
13ed5ea93d5d55ad202b276505ec6281
|
|
| BLAKE2b-256 |
84963bd9875aedcfef5c6897bcf6f161e8cd4a545ec294f2d2c0ed0d18c042b4
|
File details
Details for the file aiocli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aiocli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/5.3.0-1032-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
156d4e46b8a26ff97eb0307fa84188008645c5b1fcfb2efc079131d766ee2863
|
|
| MD5 |
eb3a0a3be153252617e35ed20dfbc244
|
|
| BLAKE2b-256 |
32aee11e5a7be76361bd44f8d113e43ae415b86a96e388dd8f4004ead8662869
|