{ "info": { "author": "Lunluen", "author_email": "mas581301@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: AsyncIO", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "\n# Aplex\n\n[![build](https://img.shields.io/travis/com/lunluen/aplex.svg?style=flat)]()\n[![coverage](https://img.shields.io/codecov/c/github/lunluen/aplex.svg?style=flat)](https://github.com/lunluen/aplex)\n[![platform]()]()\n[![supported pythons](https://img.shields.io/pypi/pyversions/aplex.svg?style=flat)]()\n[![package version](https://img.shields.io/pypi/v/aplex.svg?style=flat)]()\n[![license](https://img.shields.io/github/license/lunluen/aplex.svg?style=flat)]()\n[![maintenance](https://img.shields.io/maintenance/yes/2019.svg?style=flat)]()\n\nTranslation: \n[\u7b80\u4f53\u4e2d\u6587](https://github.com/lunluen/aplex/blob/master/README_zh_cn.md)\n|\n[\u7e41\u9ad4\u4e2d\u6587](https://github.com/lunluen/aplex/blob/master/misc/README_zh_tw.md)\n\nAplex is a Python library for combining asyncio with\nmultiprocessing and threading.\n\n- Aplex helps you run coroutines and functions in other process\n or thread with asyncio.\n- Aplex provides a usage like that of standard library `concurrent.futures`,\n which is familiar to you and intuitive.\n- Aplex lets you do load balancing in a simple way if you need.\n\n## Installation\n\nFor general users, use the package manager [pip](https://pip.pypa.io/en/stable/) to\ninstall aplex.\n\n```bash\npip install aplex\n```\n\nFor contributors, install with pipenv:\n\n```bash\ngit clone https://github.com/lunluen/aplex.git\ncd aplex\npipenv install --dev\n```\nor with setuptools\n\n```bash\ngit clone https://github.com/lunluen/aplex.git\ncd aplex\npython setup.py develop\n```\n\n## Usage\n\nDefinition to know:\n> A `work` is a `callable` you want to run with asyncio and multiprocessing or threading.\n> It can be a coroutine function or just a function.\n\nIn below case, the `work` is the coroutine function `demo`.\n\n### Submit\n\nYou can submit your work like:\n\n```python\nimport aiohttp\nfrom aplex import ProcessAsyncPoolExecutor\n\nasync def demo(url):\n async with aiohttp.request('GET', url) as response:\n return response.status\n\nif __name__ == '__main__':\n pool = ProcessAsyncPoolExecutor(pool_size=8)\n future = pool.submit(demo, 'http://httpbin.org')\n print('Status: %d.' % future.result())\n```\n\n*Note*: If you are running python on windows, `if __name__ == '__main__':`\nis necessary. That's the design of multiprocessing.\n\nResult:\n\n```bash\nStatus: 200\n```\n\n### Map\n\nFor multiple works, try `map`:\n\n```python\niterable = ('http://httpbin.org' for __ in range(10))\nfor status in pool.map(demo, iterable, timeout=10):\n print('Status: %d.' % status)\n```\n\n### Awaiting results\n\nAplex allows one to await results with loop that already exists. It's quite simple.\n\nJust set keyword argument `awaitable` to `True`!\n\nFor example:\n\n```python\npool = ProcessAsyncPoolExecutor(awaitable=True)\n```\n\nThen \n\n```python\nfuture = pool.submit(demo, 'http://httpbin.org')\nstatus = await future\n```\n\nHow about map?\n\n```python\nasync for status in pool.map(demo, iterable, timeout=10):\n print('Status: %d.' % status)\n```\n\n### Load balancing\n\nIn aplex, each worker is the process or thread on your computer. That is, they have the same capability computing.\n*But*, your works might have different workloads. Then you need a load balancer.\n\nAplex provides some useful load balancers. They are `RoundRobin`, `Random`, and `Average`. The default is `RoundRobin`.\n\nSimply set this in contruction keyword argument:\n\n```python\nfrom aplex.load_balancers import Average\n\nif __name__ == '__main__':\n pool = ProcessAsyncPoolExecutor(load_balancer=Average)\n```\n\nDone. So easy. :100:\n\nYou can also customize one:\n\n```python\nfrom aplex import LoadBalancer\n\nclass MyAwesomeLoadBalancer(LoadBalancer):\n def __init__(*args, **kwargs):\n super().__init__(*args, **kwargs) # Don't forget this.\n awesome_attribute = 'Hello Aplex!'\n\n def get_proper_worker(self):\n the_poor_guy = self.workers[0]\n return the_poor_guy\n```\n\nSee details of how to implement a load balancer at: []()\n\n\n### Worker loop factory\n\nBy the way, if you think the build-in asyncio loop is too slow:\n\n```python\nimport uvloop\n\nif __name__ == '__main__':\n pool = ProcessAsyncPoolExecutor(worker_loop_factory=uvloop.Loop)\n```\n\n## Like this?\n\nScroll up and click `Watch - Releases only` and `Star` as a thumbs up! :+1:\n\n## Any feedback?\n\nFeel free to open a issue (just don't abuse it).\n\nOr contact me: `mas581301@gmail.com` :mailbox:\n\nAnything about aplex is welcome, such like bugs, system design, variable naming, even English grammer of docstrings!\n\n## How to contribute\n\nContribution are welcome.\n\nAsking and advising are also kinds of contribution.\n\nPlease see [CONTRIBUTING.md](https://github.com/lunluen/aplex/blob/master/CONTRIBUTING.md)\n\n## License\n\n[MIT](https://github.com/lunluen/aplex/blob/master/LICENSE)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lunluen/aplex", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "aplex", "package_url": "https://pypi.org/project/aplex/", "platform": "", "project_url": "https://pypi.org/project/aplex/", "project_urls": { "Homepage": "https://github.com/lunluen/aplex" }, "release_url": "https://pypi.org/project/aplex/1.0.1/", "requires_dist": [ "uvloop ; extra == 'uvloop'" ], "requires_python": ">=3.5.0", "summary": "Run your coroutines and functions in child process or thread like the way using concurrent.futures.", "version": "1.0.1" }, "last_serial": 4803175, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "41735ce6e6c7789df1a7eec94909cd72", "sha256": "1f9e12bb3802703d475776055ded237cb64f69ccf96e496fa64374c0ad6eafab" }, "downloads": -1, "filename": "aplex-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "41735ce6e6c7789df1a7eec94909cd72", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.5.0", "size": 35096, "upload_time": "2019-02-10T20:04:00", "url": "https://files.pythonhosted.org/packages/ef/67/fc4f21422741b5cb9511f2a95d45290d8a15326c8184cfb640c47b3482dd/aplex-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c21477f83010c58fa7a85eb4d872ae71", "sha256": "e393fabe502f827fcc02b7dda68489c9b8562ed10d38a58089f73b54fbef5ea9" }, "downloads": -1, "filename": "aplex-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c21477f83010c58fa7a85eb4d872ae71", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 500730, "upload_time": "2019-02-10T20:04:04", "url": "https://files.pythonhosted.org/packages/cb/97/9af8e96a68ba698c86f5a808cd8ce50b64380d015a84ac705fc0ea088aa3/aplex-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "41735ce6e6c7789df1a7eec94909cd72", "sha256": "1f9e12bb3802703d475776055ded237cb64f69ccf96e496fa64374c0ad6eafab" }, "downloads": -1, "filename": "aplex-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "41735ce6e6c7789df1a7eec94909cd72", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.5.0", "size": 35096, "upload_time": "2019-02-10T20:04:00", "url": "https://files.pythonhosted.org/packages/ef/67/fc4f21422741b5cb9511f2a95d45290d8a15326c8184cfb640c47b3482dd/aplex-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c21477f83010c58fa7a85eb4d872ae71", "sha256": "e393fabe502f827fcc02b7dda68489c9b8562ed10d38a58089f73b54fbef5ea9" }, "downloads": -1, "filename": "aplex-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c21477f83010c58fa7a85eb4d872ae71", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 500730, "upload_time": "2019-02-10T20:04:04", "url": "https://files.pythonhosted.org/packages/cb/97/9af8e96a68ba698c86f5a808cd8ce50b64380d015a84ac705fc0ea088aa3/aplex-1.0.1.tar.gz" } ] }