Create async web requests in no time
Project description
🔀 Unparallel
Installation
pip install unparallel
Example
A simple example of doing a number of GET requests to an HTTP web service:
import asyncio
from unparallel import up
async def main():
url = "https://httpbin.org"
paths = [f"/get?i={i}" for i in range(5)]
results = await up(url, paths)
print([item["args"] for item in results])
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"
path = "/post"
payloads = [{"obj_id": i} for i in range(5)]
results = await up(url, path, 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}']
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
I was heavily inspired for this project by the blog post Making 1 million requests with python-aiohttp by Paweł Miech.
This project was generated with python-package-template
.
Project details
Release history Release notifications | RSS feed
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
Hashes for unparallel-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b609b7bfd26e98829a2b008406c8275b5642323f781ca74afc6707ef5619181c |
|
MD5 | 3328badd8f19fcdb161bd00148433778 |
|
BLAKE2b-256 | 995e8e8985eae338752296d9f442582732d535160f4924b59bde60fa4d39660f |