{ "info": { "author": "Marko Tasic", "author_email": "mtasic85@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Topic :: Software Development" ], "description": "# asyncwrap\n\nasyncwrap helps wrapping synchronous calls into asynchronous ones, and it based\non asyncio and threading modules.\n\nFor example, sqlalchemy is synchronous and not built to be compatible with\nasyncio. asyncwrap offers simple wrappers which if used in right places can make\ncode run concurrent and be faster. For more information please check examples\ndirectory.\n\nasyncwrap is library/framework agnostic and can be used with any Python >=3.5\ncode.\n\nAll you need can be found by importing single class called Async:\n```python\nfrom asyncwrap import Async\n```\n\nAsync class has following methods:\n```python\nAsync.set_default_loop\nAsync.With\nAsync.For\nAsync.Call\nAsync.ExecutorCall\nAsync.ThreadCall\n```\n\n\n# Example\n\n```python\nimport time\nimport random\nimport asyncio\nimport tempfile\nimport functools\n\nfrom asyncwrap import Async\n\n\nasync def do_async_with(loop):\n async with Async.With(tempfile.TemporaryFile()) as f:\n await Async.Call(f.write, b'hello world')\n await asyncio.sleep(random.random())\n await Async.Call(f.seek, 0)\n await asyncio.sleep(random.random())\n data = await Async.Call(f.read)\n print('do_async_with', data)\n\n\nasync def do_async_for(loop, s, e):\n async for i in Async.For(range(s, e)):\n await asyncio.sleep(random.random())\n print('do_async_for', i)\n\n\nasync def do_async_call(loop, f, t):\n r = await Async.Call(f, t)\n print('do_async_call', f, t, r)\n return r\n\n\nasync def do_async_executor_call(loop, f, t):\n r = await Async.ExecutorCall(f, t)\n print('do_async_executor_call', f, t, r)\n return r\n\n\nasync def do_async_thread_call(loop, f, t):\n r = await Async.ThreadCall(f, t)\n print('do_async_thread_call', f, t, r)\n return r\n\n\ndef blocking_sleep(t):\n time.sleep(t)\n return t\n\n\nif __name__ == '__main__':\n loop = asyncio.get_event_loop()\n Async.set_default_loop(loop)\n\n tasks = [\n # with\n asyncio.ensure_future(do_async_with(loop)),\n asyncio.ensure_future(do_async_with(loop)),\n\n # for\n asyncio.ensure_future(do_async_for(loop, 0, 10)),\n asyncio.ensure_future(do_async_for(loop, 20, 30)),\n \n # call\n asyncio.ensure_future(\n do_async_call(loop, blocking_sleep, random.random() * 5)),\n \n asyncio.ensure_future(\n do_async_call(loop, blocking_sleep, random.random() * 5)),\n\n # executor call\n asyncio.ensure_future(\n do_async_executor_call(loop, blocking_sleep, 5)),\n\n asyncio.ensure_future(\n do_async_executor_call(loop, blocking_sleep, 5)),\n\n # thread call\n asyncio.ensure_future(\n do_async_thread_call(loop, blocking_sleep, 5)),\n\n asyncio.ensure_future(\n do_async_thread_call(loop, blocking_sleep, 4)),\n\n asyncio.ensure_future(\n do_async_thread_call(loop, blocking_sleep, 3)),\n\n asyncio.ensure_future(\n do_async_thread_call(loop, blocking_sleep, 2)),\n ]\n\n loop.run_until_complete(asyncio.wait(tasks))\n loop.close()\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mtasic85/asyncwrap", "keywords": "async asyncio wrapper high-level", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "asyncwrap", "package_url": "https://pypi.org/project/asyncwrap/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/asyncwrap/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/mtasic85/asyncwrap" }, "release_url": "https://pypi.org/project/asyncwrap/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Simple asynchronous wrappers for synchronous blocking code", "version": "0.1.0" }, "last_serial": 2240699, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ce4837eeb839ebcedaa980711997cef8", "sha256": "f0e06f02cc20807309687a989cb47fbe824482cbd4b657bc9f510596f9ccaf9a" }, "downloads": -1, "filename": "asyncwrap-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ce4837eeb839ebcedaa980711997cef8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4816, "upload_time": "2016-07-24T11:14:44", "url": "https://files.pythonhosted.org/packages/56/7c/a740973060d5874d89348f3eb77e67acc4ab3db3cf5f778ededd094dd4b3/asyncwrap-0.1.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ce4837eeb839ebcedaa980711997cef8", "sha256": "f0e06f02cc20807309687a989cb47fbe824482cbd4b657bc9f510596f9ccaf9a" }, "downloads": -1, "filename": "asyncwrap-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ce4837eeb839ebcedaa980711997cef8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4816, "upload_time": "2016-07-24T11:14:44", "url": "https://files.pythonhosted.org/packages/56/7c/a740973060d5874d89348f3eb77e67acc4ab3db3cf5f778ededd094dd4b3/asyncwrap-0.1.0-py3-none-any.whl" } ] }