gevent-requests: Asynchronous Requests
gevent-requests allows you to use Requests with Gevent to make asynchronous HTTP Requests easily.
A fork from grequests <https://github.com/spyoungtech/grequests>.
It is highly recommended that you patch from the entry and do not include thread, this package does not include patch!
pip install gevent-requests
Usage is simple:
from gevent import monkey
monkey.patch_all(thread=False, select=False)
import gevent_requests
urls = [
'http://www.heroku.com',
'http://python-tablib.org',
'http://httpbin.org',
'https://shields.io',
'http://fakedomain/',
]
Create a set of unsent Requests:
>>> rs = (gevent_requests.get(u) for u in urls)
Send them all at the same time:
>>> print(gevent_requests.gmap(rs))
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>, <Response [502]>]
Optionally, in the event of a timeout or any other exception during the connection of the request, you can add an exception handler that will be called with the request and exception inside the main thread:
>>> def exception_handler(request, exception):
... print("Request failed")
>>> reqs = [
... gevent_requests.get('http://httpbin.org/delay/1', timeout=0.001),
... gevent_requests.get('http://fakedomain/'),
... gevent_requests.get('http://httpbin.org/status/500')]
>>> print(gevent_requests.gmap(reqs, exception_handler=exception_handler))
Request failed
[None, <Response [502]>, <Response [500]>]
For some speed/performance gains, you may also want to use imap instead of map. imap returns a generator of responses. Order of these responses does not map to the order of the requests you send out. The API for imap is equivalent to the API for map.
Use indexed requests in gevent, use gimap_enumerate will yield a indexed requests just like enumerate return, an index and a response:
>>> rs = (gevent_requests.get(u) for u in urls)
>>> for i in gevent_requests.gimap_enumerate(rs, size=len(urls)):
print(i)
(4, <Response [502]>)
(2, <Response [200]>)
(0, <Response [200]>)
(3, <Response [200]>)
(1, <Response [200]>)
Metadata
Release files for gevent_requests 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gevent_requests-1.1.2.tar.gz | 5.2 kB | Without provenance | Details for gevent_requests-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gevent_requests-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for gevent_requests-1.1.2-py3-none-any.whl |
Total release size: 10.9 kB
Release files / gevent_requests-1.1.2.tar.gz
| Download URL | gevent_requests-1.1.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dac139f1ff123125f1284afbd1340da341cca01133528613defaf54f56d3746
|
|
BLAKE2b-256 checksum How to use checksums |
96a43e03a6e6cbbf7ad1f9840c7b724bc24c00b4d133edaf880ee28f34a6100f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.12.3 Darwin/23.5.0
|
Release files / gevent_requests-1.1.2-py3-none-any.whl
| Download URL | gevent_requests-1.1.2-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12042f3b5d915b1f0ffc133ae288d18ae8b062068beb7d9cfc148521ad629fb7
|
|
BLAKE2b-256 checksum How to use checksums |
0331b498485bfb824ae917448d2b0589e900e2b742ffaa3af8d6e65cf1fff5cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.17.3 CPython/3.12.3 Darwin/23.5.0
|
Security for gevent_requests 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.