| Name | syncra JSON |
| Version |
1.0.3
JSON |
| download |
| home_page | None |
| Summary | A utility for creating synchronous and asynchronous compatible methods. |
| upload_time | 2024-08-22 22:38:42 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.6 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# syncra
?? Syncra provides async harmony. See the examples below to learn how to create functions and classes that work in both synchronous and asynchronous contexts.
## Features
- **Async and Sync Compatibility**: Easily create functions that work in both synchronous and asynchronous contexts.
- **Flexible Initialization**: Use `AsyncObj` for classes requiring asynchronous initialization.
- **Decorator for Async Methods**: Simplify async method usage with the `sync_compat` decorator.
## Installation
Install via pip:
```bash
pip install syncra
```
## Usage
### sync_async_factory
_Create a function that can be called synchronously or asynchronously:_
```python
from syncra import sync_async_factory
import asyncio
def sync_func(x):
return x * 2
async def async_func(x):
await asyncio.sleep(0.1)
return x * 2
syncra = sync_async_factory(sync_func, async_func)
# Usage:
result = syncra(5) # Synchronous
async def main(): # Asynchronous
result = await syncra(5)
```
### `@sync_compat` Decorator
Make an async function compatible with sync calls
```python
from syncra import sync_compat
import asyncio
@sync_compat
async def async_function(x):
await asyncio.sleep(0.1)
return x * 2
# Usage:
result = async_function(5) # Synchronous
async def main(): # Asynchronous
result = await async_function(5)
```
### `AsyncObj` Class
Create a class that can be initialized asynchronously:
```python
from syncra import AsyncObj
class MyAsyncClass(AsyncObj):
async def __ainit__(self, x):
self.x = x
# Usage:
async def main():
obj = await MyAsyncClass(10)
print(obj.x)
```
### Licence
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "syncra",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Islati // Skreet Media Inc // Wogwon Society <islati@wogwon.com>",
"download_url": "https://files.pythonhosted.org/packages/98/4a/07990e3ec96ceecb11e071b7c4014ea4d4e6bdb1cd9e03b61f3f5da33370/syncra-1.0.3.tar.gz",
"platform": null,
"description": "# syncra\r\n\r\n?? Syncra provides async harmony. See the examples below to learn how to create functions and classes that work in both synchronous and asynchronous contexts.\r\n\r\n## Features\r\n\r\n- **Async and Sync Compatibility**: Easily create functions that work in both synchronous and asynchronous contexts.\r\n- **Flexible Initialization**: Use `AsyncObj` for classes requiring asynchronous initialization.\r\n- **Decorator for Async Methods**: Simplify async method usage with the `sync_compat` decorator.\r\n\r\n## Installation\r\n\r\nInstall via pip:\r\n\r\n```bash\r\npip install syncra\r\n```\r\n\r\n## Usage\r\n\r\n### sync_async_factory\r\n\r\n_Create a function that can be called synchronously or asynchronously:_\r\n\r\n```python\r\nfrom syncra import sync_async_factory\r\nimport asyncio\r\n\r\ndef sync_func(x):\r\n return x * 2\r\n\r\n\r\nasync def async_func(x):\r\n await asyncio.sleep(0.1)\r\n return x * 2\r\n\r\n\r\nsyncra = sync_async_factory(sync_func, async_func)\r\n\r\n# Usage:\r\nresult = syncra(5) # Synchronous\r\n\r\n\r\nasync def main(): # Asynchronous\r\n result = await syncra(5)\r\n```\r\n\r\n### `@sync_compat` Decorator\r\n\r\nMake an async function compatible with sync calls\r\n\r\n```python\r\nfrom syncra import sync_compat\r\nimport asyncio\r\n\r\n\r\n@sync_compat\r\nasync def async_function(x):\r\n await asyncio.sleep(0.1)\r\n return x * 2\r\n\r\n\r\n# Usage:\r\nresult = async_function(5) # Synchronous\r\n\r\n\r\nasync def main(): # Asynchronous\r\n result = await async_function(5)\r\n\r\n```\r\n\r\n\r\n### `AsyncObj` Class\r\n\r\nCreate a class that can be initialized asynchronously:\r\n\r\n```python\r\nfrom syncra import AsyncObj\r\n\r\n\r\nclass MyAsyncClass(AsyncObj):\r\n async def __ainit__(self, x):\r\n self.x = x\r\n\r\n\r\n# Usage:\r\nasync def main():\r\n obj = await MyAsyncClass(10)\r\n print(obj.x)\r\n```\r\n\r\n### Licence\r\nThis project is licensed under the MIT License.\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A utility for creating synchronous and asynchronous compatible methods.",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/islati/syncra"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e5a3d8e59aae7787f4847146760e7de930a966fd4aae5c4aafa2e0cd877db700",
"md5": "bc9263de608788270e0a8ceb6abcd716",
"sha256": "867a5018a3bfd8491125d8e4d483383b16f54210deb07f4551ddca3043821470"
},
"downloads": -1,
"filename": "syncra-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bc9263de608788270e0a8ceb6abcd716",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 4809,
"upload_time": "2024-08-22T22:38:40",
"upload_time_iso_8601": "2024-08-22T22:38:40.997406Z",
"url": "https://files.pythonhosted.org/packages/e5/a3/d8e59aae7787f4847146760e7de930a966fd4aae5c4aafa2e0cd877db700/syncra-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "984a07990e3ec96ceecb11e071b7c4014ea4d4e6bdb1cd9e03b61f3f5da33370",
"md5": "bf02c73002c90295a73bfdcf3c248f60",
"sha256": "aec5b3ab0332e45ed7ae44aa7338566155695c9f1cfb1609165850a3aa3fa126"
},
"downloads": -1,
"filename": "syncra-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "bf02c73002c90295a73bfdcf3c248f60",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4366,
"upload_time": "2024-08-22T22:38:42",
"upload_time_iso_8601": "2024-08-22T22:38:42.591390Z",
"url": "https://files.pythonhosted.org/packages/98/4a/07990e3ec96ceecb11e071b7c4014ea4d4e6bdb1cd9e03b61f3f5da33370/syncra-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-22 22:38:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "islati",
"github_project": "syncra",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "syncra"
}