asynctranslator


Nameasynctranslator JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryTyped Async-to-sync & Sync-to-async utility
upload_time2023-04-23 16:17:20
maintainer
docs_urlNone
authorPredeactor
requires_python>=3.7,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ASyncTranslator

A package to transform your **sync** methods to **async** methods and to turn **async** methods to **sync** methods.

🤩 ✨ **FINALLY TYPED EDITION!!!** ❤️ 🤌

This is an heavy inspiration from Django's implementation.
Please see https://github.com/django/asgiref/blob/30d891fab0a7caa265bda0cbe04bb35a00a3b3b9/asgiref/sync.py for original reference.

## Show me an example, pretty please.

Here you go!

To transform from an **async** to **sync** method:
```py
from asynctranslator import async_to_sync

async def my_async_func(food_name: str) -> int:
    print(f"{food_name} are my favorite!")
    return 42

def main():
    final_func = async_to_sync(my_async_func)
    result = final_func("Cookies")
    print(result)  # We got "42"!

main()
```

And now, to transform from a **sync** to **async** method:
```py
import asyncio
from asynctranslator import sync_to_async

def my_async_func(food_name: str) -> int:
    print(f"{food_name} are my favorite!")
    return 42

async def main():
    final_func = sync_to_async(my_async_func)
    result = await final_func("Cookies")
    print(result)  # We got "42"!

asyncio.run(main())
```

But you can also use it as a decorator!

```py
import asyncio
from asynctranslator import sync_to_async

@sync_to_async
def my_async_func(food_name: str) -> int:
    print(f"{food_name} are my favorite!")
    return 42

async def main():
    result = await my_async_func("Cookies")
    print(result)

asyncio.run(main())
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "asynctranslator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Predeactor",
    "author_email": "pro.julien.mauroy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/18/ed/c70a77dbfcd57d2ce5c705e69f98ad8bb3df09f93e47ccd0baeeec822a9b/asynctranslator-1.0.1.tar.gz",
    "platform": null,
    "description": "# ASyncTranslator\n\nA package to transform your **sync** methods to **async** methods and to turn **async** methods to **sync** methods.\n\n\ud83e\udd29 \u2728 **FINALLY TYPED EDITION!!!** \u2764\ufe0f \ud83e\udd0c\n\nThis is an heavy inspiration from Django's implementation.\nPlease see https://github.com/django/asgiref/blob/30d891fab0a7caa265bda0cbe04bb35a00a3b3b9/asgiref/sync.py for original reference.\n\n## Show me an example, pretty please.\n\nHere you go!\n\nTo transform from an **async** to **sync** method:\n```py\nfrom asynctranslator import async_to_sync\n\nasync def my_async_func(food_name: str) -> int:\n    print(f\"{food_name} are my favorite!\")\n    return 42\n\ndef main():\n    final_func = async_to_sync(my_async_func)\n    result = final_func(\"Cookies\")\n    print(result)  # We got \"42\"!\n\nmain()\n```\n\nAnd now, to transform from a **sync** to **async** method:\n```py\nimport asyncio\nfrom asynctranslator import sync_to_async\n\ndef my_async_func(food_name: str) -> int:\n    print(f\"{food_name} are my favorite!\")\n    return 42\n\nasync def main():\n    final_func = sync_to_async(my_async_func)\n    result = await final_func(\"Cookies\")\n    print(result)  # We got \"42\"!\n\nasyncio.run(main())\n```\n\nBut you can also use it as a decorator!\n\n```py\nimport asyncio\nfrom asynctranslator import sync_to_async\n\n@sync_to_async\ndef my_async_func(food_name: str) -> int:\n    print(f\"{food_name} are my favorite!\")\n    return 42\n\nasync def main():\n    result = await my_async_func(\"Cookies\")\n    print(result)\n\nasyncio.run(main())\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Typed Async-to-sync & Sync-to-async utility",
    "version": "1.0.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a25f0872b4bc91d2ac6078756c1fffd5aeb4b67bbceeec01674e9b0809d7d855",
                "md5": "d8d5e3b4dd181a93c17b34174c90f69d",
                "sha256": "325407ccf95caa9de2dbfb247cb8bd2aa2288c93364638b8f21fcfebca81b056"
            },
            "downloads": -1,
            "filename": "asynctranslator-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d8d5e3b4dd181a93c17b34174c90f69d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 15456,
            "upload_time": "2023-04-23T16:17:19",
            "upload_time_iso_8601": "2023-04-23T16:17:19.537070Z",
            "url": "https://files.pythonhosted.org/packages/a2/5f/0872b4bc91d2ac6078756c1fffd5aeb4b67bbceeec01674e9b0809d7d855/asynctranslator-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "18edc70a77dbfcd57d2ce5c705e69f98ad8bb3df09f93e47ccd0baeeec822a9b",
                "md5": "5723c52522f90ef99e7e4a99f63abff7",
                "sha256": "4061a782f2b7bf976797cb6363106ea9e740ebca022f167170cc81c25f6104d8"
            },
            "downloads": -1,
            "filename": "asynctranslator-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5723c52522f90ef99e7e4a99f63abff7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 11544,
            "upload_time": "2023-04-23T16:17:20",
            "upload_time_iso_8601": "2023-04-23T16:17:20.782969Z",
            "url": "https://files.pythonhosted.org/packages/18/ed/c70a77dbfcd57d2ce5c705e69f98ad8bb3df09f93e47ccd0baeeec822a9b/asynctranslator-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-23 16:17:20",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "asynctranslator"
}
        
Elapsed time: 1.31916s