# Hey, Sync!
This package will allow you to convert an async function or a class (that has async methods) to a sync version.
The new class name will be set as `<OLD CLASS NAME>Sync`
## Installation
`pip install heysync`
## Usage
### Async Functions
You can convert async functions to sync function by:
1. Normal usage:
```python
from heysync import async_to_sync_func
async def async_func() -> str:
return "Hey there"
sync_func = async_to_sync_func(async_func)
# now you can call sync_func in the usual way
sync_func() # Hey there
```
2. As a decorator:
```python
from heysync import async_to_sync_func
@async_to_sync_func
async def some_func() -> str:
return "boo"
some_func() # boo
```
### Classes
You can also convert async classes:
```python
from heysync import make_sync_class
# a class with async methods
class Foo:
def __init__(self, x: int) -> None:
self.x = x
async def __aenter__(self):
self.x += 2
await async_func()
return self
async def __aexit__(self, exc_type, exc_value, exc_tb) -> None:
self.x -= 1
await async_func()
async def my_func(self) -> str:
return f"Output is {self.x}"
FooSync = make_sync_class(Foo)
with Foo(7) as foo:
foo.my_func() # Output is 9
foo.my_func() # Output is 8
```
Raw data
{
"_id": null,
"home_page": "https://github.com/oren0e/heysync",
"name": "heysync",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "Async,Async-to-Sync,Utility",
"author": "oren0e",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/dc/4c/cd24a2d6553cff6c22f18c250fa8514a8526550cbb9a5f856c0f3b76df36/heysync-1.0.1.tar.gz",
"platform": null,
"description": "# Hey, Sync!\n\nThis package will allow you to convert an async function or a class (that has async methods) to a sync version. \nThe new class name will be set as `<OLD CLASS NAME>Sync`\n\n## Installation\n\n`pip install heysync`\n\n## Usage\n\n### Async Functions\n\nYou can convert async functions to sync function by:\n\n1. Normal usage:\n\n```python\nfrom heysync import async_to_sync_func\n\nasync def async_func() -> str:\n return \"Hey there\"\n\nsync_func = async_to_sync_func(async_func)\n\n# now you can call sync_func in the usual way\nsync_func() # Hey there\n```\n\n2. As a decorator:\n\n```python\nfrom heysync import async_to_sync_func\n\n@async_to_sync_func\nasync def some_func() -> str:\n return \"boo\"\n\nsome_func() # boo\n```\n\n### Classes\n\nYou can also convert async classes:\n\n```python\nfrom heysync import make_sync_class\n\n# a class with async methods\nclass Foo:\n def __init__(self, x: int) -> None:\n self.x = x\n\n async def __aenter__(self):\n self.x += 2\n await async_func()\n return self\n\n async def __aexit__(self, exc_type, exc_value, exc_tb) -> None:\n self.x -= 1\n await async_func()\n\n async def my_func(self) -> str:\n return f\"Output is {self.x}\"\n\nFooSync = make_sync_class(Foo)\nwith Foo(7) as foo:\n foo.my_func() # Output is 9\nfoo.my_func() # Output is 8\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Hey, make async functions and classes sync",
"version": "1.0.1",
"split_keywords": [
"async",
"async-to-sync",
"utility"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "286fa117810916d4d2fd8f1aaa03b05d",
"sha256": "e8517f03334dcc9ef0302126edad70ed75630646ed57f534cec45e8464ce4423"
},
"downloads": -1,
"filename": "heysync-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "286fa117810916d4d2fd8f1aaa03b05d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 6548,
"upload_time": "2022-12-27T23:36:02",
"upload_time_iso_8601": "2022-12-27T23:36:02.165467Z",
"url": "https://files.pythonhosted.org/packages/1a/61/01b61560e1fb89089e500f1cd8023eb4f97e354cd2ae8ec51ec0ea327323/heysync-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "d1f162b40d667b6617cf0d75e7d5fdfa",
"sha256": "bdb695f8ccc16241f598f78bf5e4aef84e9457b64cea6da736cb54ef32354754"
},
"downloads": -1,
"filename": "heysync-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "d1f162b40d667b6617cf0d75e7d5fdfa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 6404,
"upload_time": "2022-12-27T23:36:03",
"upload_time_iso_8601": "2022-12-27T23:36:03.239186Z",
"url": "https://files.pythonhosted.org/packages/dc/4c/cd24a2d6553cff6c22f18c250fa8514a8526550cbb9a5f856c0f3b76df36/heysync-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-27 23:36:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "oren0e",
"github_project": "heysync",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "heysync"
}