Create async web requests in no time
Project description
🔀 Unparallel
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 and aims to support its rich set of features.
Installation
pip install unparallel
Example
A simple example of doing several GET requests to an HTTP web service:
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:
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.
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.
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.
Contributing
As this project is still in early development, I'm happy for any feedback and contributions! Please refer to the contributing guidelines for details.
License
This project is licensed under the terms of the MIT license. See LICENSE for more details.
Credits
This project was heavily inspired by the blog post Making 1 million requests with python-aiohttp by Paweł Miech.
I created this project with python-package-template.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unparallel-0.5.0.tar.gz.
File metadata
- Download URL: unparallel-0.5.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b18db5b4395c285c2ba5c155b0e1fb6df119f3e121af07dbb97d974805807a31
|
|
| MD5 |
ba9d90df244461cddf3bf854906b4229
|
|
| BLAKE2b-256 |
61a25710404dbed3b8b5e23183c9bddc6f86f59c2e38ac55b2a6502f22e80dd7
|
Provenance
The following attestation bundles were made for unparallel-0.5.0.tar.gz:
Publisher:
publish.yml on RafaelWO/unparallel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unparallel-0.5.0.tar.gz -
Subject digest:
b18db5b4395c285c2ba5c155b0e1fb6df119f3e121af07dbb97d974805807a31 - Sigstore transparency entry: 584252297
- Sigstore integration time:
-
Permalink:
RafaelWO/unparallel@a1718a75fabf0609a195ff0e03d46a16e16bed67 -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/RafaelWO
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a1718a75fabf0609a195ff0e03d46a16e16bed67 -
Trigger Event:
push
-
Statement type:
File details
Details for the file unparallel-0.5.0-py3-none-any.whl.
File metadata
- Download URL: unparallel-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c85813869d5cce00758820cc0be251bd08c9ab511bac9e227d1da73768a40a44
|
|
| MD5 |
d2225bbb82cc010796a9cd4f450440df
|
|
| BLAKE2b-256 |
84c85d02e452a6b063a4fe666a800b959eeff93a1048f21f12931e0f0e32144b
|
Provenance
The following attestation bundles were made for unparallel-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on RafaelWO/unparallel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unparallel-0.5.0-py3-none-any.whl -
Subject digest:
c85813869d5cce00758820cc0be251bd08c9ab511bac9e227d1da73768a40a44 - Sigstore transparency entry: 584252298
- Sigstore integration time:
-
Permalink:
RafaelWO/unparallel@a1718a75fabf0609a195ff0e03d46a16e16bed67 -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/RafaelWO
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a1718a75fabf0609a195ff0e03d46a16e16bed67 -
Trigger Event:
push
-
Statement type: