Name | aiocallback JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | A library for helping configure callbacks with asyncio and aiosignal |
upload_time | 2024-09-21 15:07:23 |
maintainer | None |
docs_url | None |
author | Vizonex |
requires_python | None |
license | None |
keywords |
event callbacks
callbacks
asyncio
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# aiocallback:
[![PyPI version](https://badge.fury.io/py/aiocallback.svg)](https://badge.fury.io/py/aiocallback)
![PyPI - Downloads](https://img.shields.io/pypi/dm/aiocallback)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Tests](/aiocallback/actions/workflows/tests.yml/badge.svg)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
An asynchronous helper for writing custom event wrapper class functions and is a good framework for library development made with good typehinting that is built around [aiosignal](https://github.com/aio-libs/aiosignal) under the hood with a few modifications added onto it for better typehinting and easy usage.
One of my biggest pet peves of all time is when **callbacks are not being properly hinted at**. This library aims to fix that for vscode and other ides such as when calling the send() function.
<img src="Typehinting-Example.png" width="500px"/>
# Usage:
## Dependencies
## Installing
The easiest way is to install **aiocallback** is from PyPI using pip:
```sh
pip install aiocallback
```
## Running
First, import the library.
```python
from aiocallback import event, subclassevent, contextevent
import asyncio
class Config:
"""an example of configuring callbacks"""
# NOTE: Typehinting will be passed to other objects
# Thanks in largepart to ParamSpec and Concatenate
# NOTE: @event considers the function to be an abstract method, However you can use a subclassevent to retain typechecking if you need something that isn't so abstract
@event
async def on_print(self, cb:str):
"""callbacks for a print method"""
@subclassevent
async def on_nonabstract(self, cb:str):
"""a nonabstract method can be called with other events as being part of the signal"""
print(f"I am callable! \"{cb}\"")
cfg = Config()
# You can also call the append method just like with aiosignal as ours is primarly a subclass of it.
@cfg.on_print
async def test(cb:str):
print(f"called test {cb}")
async def main():
# This uses aiosignal under the hood so remeber to freeze the callbacks when your setup is complete
cfg.on_print.freeze()
cfg.on_nonabstract.freeze()
await cfg.on_print.send("Hello world")
await cfg.on_nonabstract.send("Hello world")
if __name__ == "__main__":
asyncio.run(main())
```
# TODO:
[] pypi release
Raw data
{
"_id": null,
"home_page": null,
"name": "aiocallback",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "event callbacks, callbacks, asyncio",
"author": "Vizonex",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/9b/23/06efc09ece0f4cdb585077d9230431183f0d16edfeef358838c3d3003f8e/aiocallback-0.1.0.tar.gz",
"platform": null,
"description": "# aiocallback:\r\n[![PyPI version](https://badge.fury.io/py/aiocallback.svg)](https://badge.fury.io/py/aiocallback)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dm/aiocallback)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n![Tests](/aiocallback/actions/workflows/tests.yml/badge.svg)\r\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\r\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\r\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\r\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)\r\n\r\n\r\nAn asynchronous helper for writing custom event wrapper class functions and is a good framework for library development made with good typehinting that is built around [aiosignal](https://github.com/aio-libs/aiosignal) under the hood with a few modifications added onto it for better typehinting and easy usage. \r\n\r\n\r\nOne of my biggest pet peves of all time is when **callbacks are not being properly hinted at**. This library aims to fix that for vscode and other ides such as when calling the send() function.\r\n\r\n<img src=\"Typehinting-Example.png\" width=\"500px\"/>\r\n\r\n\r\n\r\n# Usage:\r\n\r\n## Dependencies\r\n\r\n## Installing\r\n\r\nThe easiest way is to install **aiocallback** is from PyPI using pip:\r\n\r\n```sh\r\npip install aiocallback\r\n```\r\n\r\n## Running\r\n\r\nFirst, import the library.\r\n\r\n```python\r\nfrom aiocallback import event, subclassevent, contextevent\r\nimport asyncio\r\n\r\nclass Config:\r\n \"\"\"an example of configuring callbacks\"\"\"\r\n\r\n # NOTE: Typehinting will be passed to other objects \r\n # Thanks in largepart to ParamSpec and Concatenate\r\n \r\n # NOTE: @event considers the function to be an abstract method, However you can use a subclassevent to retain typechecking if you need something that isn't so abstract\r\n @event\r\n async def on_print(self, cb:str):\r\n \"\"\"callbacks for a print method\"\"\"\r\n\r\n @subclassevent\r\n async def on_nonabstract(self, cb:str):\r\n \"\"\"a nonabstract method can be called with other events as being part of the signal\"\"\"\r\n print(f\"I am callable! \\\"{cb}\\\"\")\r\n\r\n\r\n\r\n\r\ncfg = Config()\r\n# You can also call the append method just like with aiosignal as ours is primarly a subclass of it.\r\n@cfg.on_print\r\nasync def test(cb:str):\r\n print(f\"called test {cb}\")\r\n\r\n\r\n\r\nasync def main():\r\n # This uses aiosignal under the hood so remeber to freeze the callbacks when your setup is complete\r\n cfg.on_print.freeze()\r\n cfg.on_nonabstract.freeze()\r\n\r\n await cfg.on_print.send(\"Hello world\")\r\n await cfg.on_nonabstract.send(\"Hello world\")\r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(main())\r\n\r\n```\r\n\r\n# TODO:\r\n [] pypi release\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A library for helping configure callbacks with asyncio and aiosignal",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"event callbacks",
" callbacks",
" asyncio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9b2306efc09ece0f4cdb585077d9230431183f0d16edfeef358838c3d3003f8e",
"md5": "4c40482fb47bd317d85678b869df8501",
"sha256": "7a70c9ea83df38b91bbc8837180429f239c861e7f1f86e9fa4e6a785115592ff"
},
"downloads": -1,
"filename": "aiocallback-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4c40482fb47bd317d85678b869df8501",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5367,
"upload_time": "2024-09-21T15:07:23",
"upload_time_iso_8601": "2024-09-21T15:07:23.164830Z",
"url": "https://files.pythonhosted.org/packages/9b/23/06efc09ece0f4cdb585077d9230431183f0d16edfeef358838c3d3003f8e/aiocallback-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-21 15:07:23",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "aiocallback"
}