Easiest way to make tons of get/post requests with aiohttp.
Project description
ez_aio
Easiest way to make tons of get/post requests with aiohttp.
You need DIY to get/post with different proxy/headers/cookies, or delete/patch/put request.
Singel GET
url = 'https://www.baidu.com'
result = aio.get(url)[0] # return a list by default
Singel GET and print
url = 'https://www.baidu.com'
aio.get(url, func=print)
x100 GET
urls = ['https://www.baidu.com'] * 100
results = aio.get(urls)
x100 POST
urls = ['https://httpbin.org/post'] * 100
data = [{'a': n} for n in range(100)]
results = [aio.post(urls, data=data, func=print)]
Singel GET speedtest
# requests might raise errors
a = timeit.repeat("requests.get('https://www.baidu.com', headers=header0)",
setup='import requests\nfrom ez_aio import header0', repeat=10, number=1)
b = timeit.repeat("aio.get(['https://www.baidu.com'], headers=header0)",
setup='from ez_aio import aio, header0', repeat=10, number=1)
for x, y in ((a, 'requests'), (b, 'aiohttp')):
print(y)
print(f'{mean(x):.3f} ± {stdev(x):.3f} s, (range) [{min(x):.3f}, {max(x):.3f}]')
def
get(urls, binary=False, func=None, fdata=None, li=99, forced=True, ssl=False,
proxy=None, headers=None, cookies=None):
post(urls, data=None, binary=False, func=None, fdata=None, li=99, forced=True,
ssl=False, proxy=None, headers=None, cookies=None):
- urls: url or list of url
- data: post(*, data=data[i], *) Change to json=data[i] if you want.
- binary: result = response.text() if binary else response.read()
- func: return func(result, *) if func else return result
- fdata: func(result, fdata[i] if fdata else func(result)
- li: max of session, 99 be default
- forced: only return response.status in [200, 403] if forced
- ssl: ssl
- proxy: proxy
- headers: headers
- cookies: cookies
- return: func(result, *) if func else result
More
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
ez_aio-0.0.2.tar.gz
(3.2 kB
view details)
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 ez_aio-0.0.2.tar.gz.
File metadata
- Download URL: ez_aio-0.0.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9534647b632003a7268f3fafbfa763f8ae2b803ee3a3626cd5eebb625bfd5488
|
|
| MD5 |
62229443b8574c9f8290ae553480f2c7
|
|
| BLAKE2b-256 |
8a2122cf7b84c7bef89789fbb30aa78606e33ed1c8acea962d41c8a3a94118c2
|
File details
Details for the file ez_aio-0.0.2-py3-none-any.whl.
File metadata
- Download URL: ez_aio-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
196970addf12cf97c9b66ec32297082a2fb728122b3e8cb690a074f9f2fc83a3
|
|
| MD5 |
be7a68b9eaac5f0cb081d2736d8f8c71
|
|
| BLAKE2b-256 |
5945f8c64eadbc31117fc389b9bb4ef4be782267b7801b72d9f89b05e6b9d80a
|