geventhttpclient is an asynchronous HTTP client library specifically designed to work with gevent, providing non-blocking HTTP requests. It is currently at version 2.3.9 and has a moderate release cadence, with updates typically several times a year as needed for bug fixes and compatibility.
pip install geventhttpclientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize gevent's monkey patching, create an `HTTPClient` instance, perform a GET request, and handle the response. It highlights the importance of `monkey.patch_all()` and proper client closure.
Ensure `from gevent import monkey; monkey.patch_all()` is called at the very beginning of your application's lifecycle, before any blocking I/O is performed.
Surround client usage with a `try...finally` block calling `client.close()` or use a `with` statement: `with HTTPClient.from_url(...) as client: ...`
Always set `raise_request_exception=True` when initializing the client or on the request call (`client.get('/path', raise_request_exception=True)`) to ensure exceptions are raised for both network/client errors and HTTP status errors. If `raise_request_exception` is not used, wrap client calls in a `try...except AttributeError` block to handle cases where `response.status` might not exist, and then proceed to check `response.status` for HTTP error codes (e.g., `if not 200 <= response.status < 300: # handle error`).For large responses, read the body in chunks using `response.read(chunk_size)` or iterate over the response object if it supports chunked reading to process data incrementally.
Ensure a C compiler is installed in your environment before installing `gevent`. For Debian/Ubuntu-based systems, run `apt-get update && apt-get install build-essential`. For Alpine-based systems, run `apk add alpine-sdk`.
pip install geventhttpclient
Ensure you are correctly initializing an `HTTPClient` or `Session` object and passing the client instance where required, instead of a string. For example, pass the client object to methods that expect it.
Increase the `network_timeout` or `connection_timeout` parameters when initializing your `HTTPClient` instance. For example: `client = HTTPClient(host, network_timeout=10.0, connection_timeout=5.0)`.
Ensure your `certifi` package is up to date (`pip install --upgrade certifi`). If using custom certificates, verify your `ssl_options` are configured correctly. For general gevent applications, ensure `gevent.monkey.patch_all()` is called at the very beginning of your application before any other imports that might use standard library I/O.