# 🔀 Unparallel
<!-- --8<-- [start:index] -->
<div align="center" markdown="1">
Create async HTTP requests with Python in no time.
[](https://github.com/RafaelWO/unparallel/actions?query=workflow%3Atest)

<br>
[](https://pypi.org/project/unparallel/)
[](https://pypi.org/project/unparallel/)
<br>
[](https://github.com/astral-sh/ruff)
[](https://github.com/PyCQA/bandit)
[](https://github.com/RafaelWO/unparallel/blob/main/.pre-commit-config.yaml)
[](https://github.com/RafaelWO/unparallel/blob/main/LICENSE)
<br>
[](https://rafaelwo.github.io/unparallel/)
[](https://squidfunk.github.io/mkdocs-material/)
</div>
With Unparallel you can easily create thousands of web requests in an efficient way leveraging Python's async capabilities.
Unparallel is built on top of [HTTPX](https://github.com/encode/httpx/) and aims to support its rich set of features.
## Installation
```bash
pip install unparallel
```
## Example
A simple example of doing several GET requests to an HTTP web service:
```python
import asyncio
from unparallel import up
async def main():
urls = [f"https://httpbin.org/get?i={i}" for i in range(5)]
results = await up(urls)
print([item["args"] for item in results])
if __name__ == "__main__":
asyncio.run(main())
```
This prints:
```
Making async requests: 100%|███████████| 5/5 [00:00<00:00, 9.98it/s]
[{'i': '0'}, {'i': '1'}, {'i': '2'}, {'i': '3'}, {'i': '4'}]
```
Similarly, we can do a bunch of POST requests. This time we will use a single path but multiple payloads:
```python
import asyncio
from unparallel import up
async def main():
url = "https://httpbin.org/post"
payloads = [{"obj_id": i} for i in range(5)]
results = await up(url, method="post", payloads=payloads)
print([item["data"] for item in results])
asyncio.run(main())
```
This prints:
```
Making async requests: 100%|███████████| 5/5 [00:00<00:00, 9.98it/s]
['{"obj_id": 0}', '{"obj_id": 1}', '{"obj_id": 2}', '{"obj_id": 3}', '{"obj_id": 4}']
```
For more details on the usage and examples, check out the [docs][docs-usage].
## Why unparallel? Why async?
Async is a really powerful feature - especially when you have to wait for I/O.
When we create HTTP requests synchronously we have to wait for every response before we can start with the next request.
If we utilize asynchronous programming, our runtime thread can do other work (other requests) during those periods of waiting.
Here is an example of making 20 web requests synchronously vs. asynchronously via `unparallel`.
![Sync-vs-Async][sync-async-gif]
As you can see, the async version finishes in less than a second while the sync code runs for around 10 seconds.
The difference gets even more drastic if you create much more requests.
You can find the sync/async code in the [docs folder](https://github.com/RafaelWO/unparallel/blob/main/docs/sync_async/).
## Contributing
As this project is still in early development, I'm happy for any feedback and contributions!
Please refer to the [contributing guidelines][contrib] for details.
## License
This project is licensed under the terms of the `MIT` license. See [LICENSE](https://github.com/RafaelWO/unparallel/blob/main/LICENSE) for more details.
## Credits
This project was heavily inspired by the blog post [Making 1 million requests with python-aiohttp](https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html) by Paweł Miech.
I created this project with [python-package-template](https://github.com/TezRomacH/python-package-template).
<!-- --8<-- [end:index] -->
[docs-usage]: https://rafaelwo.github.io/unparallel/latest/usage/
[sync-async-gif]: https://raw.githubusercontent.com/RafaelWO/unparallel/main/docs/assets/sync-vs-async.gif
[contrib]: https://github.com/RafaelWO/unparallel/blob/main/CONTRIBUTING.md
Raw data
{
"_id": null,
"home_page": "https://github.com/RafaelWO/unparallel",
"name": "unparallel",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "async, http, requests, network",
"author": "RafaelWO",
"author_email": "weingartner.rafael@hotmail.com",
"download_url": "https://files.pythonhosted.org/packages/aa/3d/3a2b63e1aa9e5a0fa88abd942b6ded9f8dfcb28729e19da2fda2645698de/unparallel-0.4.0.tar.gz",
"platform": null,
"description": "# \ud83d\udd00 Unparallel\n\n<!-- --8<-- [start:index] -->\n\n<div align=\"center\" markdown=\"1\">\n\nCreate async HTTP requests with Python in no time.\n\n[](https://github.com/RafaelWO/unparallel/actions?query=workflow%3Atest)\n\n<br>\n[](https://pypi.org/project/unparallel/)\n[](https://pypi.org/project/unparallel/)\n<br>\n[](https://github.com/astral-sh/ruff)\n[](https://github.com/PyCQA/bandit)\n[](https://github.com/RafaelWO/unparallel/blob/main/.pre-commit-config.yaml)\n[](https://github.com/RafaelWO/unparallel/blob/main/LICENSE)\n<br>\n[](https://rafaelwo.github.io/unparallel/)\n[](https://squidfunk.github.io/mkdocs-material/)\n\n</div>\n\nWith Unparallel you can easily create thousands of web requests in an efficient way leveraging Python's async capabilities.\n\nUnparallel is built on top of [HTTPX](https://github.com/encode/httpx/) and aims to support its rich set of features.\n\n## Installation\n\n```bash\npip install unparallel\n```\n\n## Example\nA simple example of doing several GET requests to an HTTP web service:\n\n```python\nimport asyncio\n\nfrom unparallel import up\n\n\nasync def main():\n urls = [f\"https://httpbin.org/get?i={i}\" for i in range(5)]\n results = await up(urls)\n print([item[\"args\"] for item in results])\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nThis prints:\n```\nMaking async requests: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5/5 [00:00<00:00, 9.98it/s]\n[{'i': '0'}, {'i': '1'}, {'i': '2'}, {'i': '3'}, {'i': '4'}]\n```\n\n\nSimilarly, we can do a bunch of POST requests. This time we will use a single path but multiple payloads:\n\n```python\nimport asyncio\n\nfrom unparallel import up\n\n\nasync def main():\n url = \"https://httpbin.org/post\"\n payloads = [{\"obj_id\": i} for i in range(5)]\n results = await up(url, method=\"post\", payloads=payloads)\n print([item[\"data\"] for item in results])\n\n\nasyncio.run(main())\n```\n\nThis prints:\n```\nMaking async requests: 100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 5/5 [00:00<00:00, 9.98it/s]\n['{\"obj_id\": 0}', '{\"obj_id\": 1}', '{\"obj_id\": 2}', '{\"obj_id\": 3}', '{\"obj_id\": 4}']\n```\n\nFor more details on the usage and examples, check out the [docs][docs-usage].\n\n## Why unparallel? Why async?\nAsync is a really powerful feature - especially when you have to wait for I/O.\nWhen we create HTTP requests synchronously we have to wait for every response before we can start with the next request.\nIf we utilize asynchronous programming, our runtime thread can do other work (other requests) during those periods of waiting.\n\nHere is an example of making 20 web requests synchronously vs. asynchronously via `unparallel`.\n\n![Sync-vs-Async][sync-async-gif]\n\nAs you can see, the async version finishes in less than a second while the sync code runs for around 10 seconds.\nThe difference gets even more drastic if you create much more requests.\n\nYou can find the sync/async code in the [docs folder](https://github.com/RafaelWO/unparallel/blob/main/docs/sync_async/).\n\n## Contributing\nAs this project is still in early development, I'm happy for any feedback and contributions!\nPlease refer to the [contributing guidelines][contrib] for details.\n\n## License\n\nThis project is licensed under the terms of the `MIT` license. See [LICENSE](https://github.com/RafaelWO/unparallel/blob/main/LICENSE) for more details.\n\n## Credits\nThis project was heavily inspired by the blog post [Making 1 million requests with python-aiohttp](https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html) by Pawe\u0142 Miech.\n\nI created this project with [python-package-template](https://github.com/TezRomacH/python-package-template).\n\n<!-- --8<-- [end:index] -->\n\n[docs-usage]: https://rafaelwo.github.io/unparallel/latest/usage/\n[sync-async-gif]: https://raw.githubusercontent.com/RafaelWO/unparallel/main/docs/assets/sync-vs-async.gif\n[contrib]: https://github.com/RafaelWO/unparallel/blob/main/CONTRIBUTING.md\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Create async web requests in no time",
"version": "0.4.0",
"project_urls": {
"Homepage": "https://github.com/RafaelWO/unparallel",
"Repository": "https://github.com/RafaelWO/unparallel"
},
"split_keywords": [
"async",
" http",
" requests",
" network"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f2a469978b5b5af930e81e82fef0b40a2d97b91df4af874582f697d6944852e1",
"md5": "4c5fef7a49856ec48308814c10c9364b",
"sha256": "866b9f76a3fef72c7826925700c6743320d58d00785a10bb6a06ead4e9bc689d"
},
"downloads": -1,
"filename": "unparallel-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c5fef7a49856ec48308814c10c9364b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 9104,
"upload_time": "2024-06-02T09:11:23",
"upload_time_iso_8601": "2024-06-02T09:11:23.691546Z",
"url": "https://files.pythonhosted.org/packages/f2/a4/69978b5b5af930e81e82fef0b40a2d97b91df4af874582f697d6944852e1/unparallel-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aa3d3a2b63e1aa9e5a0fa88abd942b6ded9f8dfcb28729e19da2fda2645698de",
"md5": "7d3a1f07b8c3dfae3771544b6571b102",
"sha256": "92a7aba2f66ab05445ecc6fd6fbc353de8de2f6698b51467f9a32277a718bb76"
},
"downloads": -1,
"filename": "unparallel-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "7d3a1f07b8c3dfae3771544b6571b102",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 10339,
"upload_time": "2024-06-02T09:11:25",
"upload_time_iso_8601": "2024-06-02T09:11:25.196669Z",
"url": "https://files.pythonhosted.org/packages/aa/3d/3a2b63e1aa9e5a0fa88abd942b6ded9f8dfcb28729e19da2fda2645698de/unparallel-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-02 09:11:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RafaelWO",
"github_project": "unparallel",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "unparallel"
}