Registry / http-networking / geventhttpclient

geventhttpclient

JSON →
library2.3.9pypypi✓ verified 30d ago

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 geventhttpclient
INSTALL
IMPORT
SIG · GEVENTHTTPCLIENT
G
geventhttpclient
http-networkingpythonv2.3.9
Install
3.1s avg
Import
350ms
Disk
38MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.3.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 3.7s
py 3.11
✓ —
✓ 3.1s
py 3.12
✓ —
✓ 2.7s
py 3.13
✓ —
✓ 2.9s
py 3.9
✕ build_error
✕ build_error
38MB installed
● package 38MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPClient
✓ from geventhttpclient import HTTPClient
HTTPClientPool
✓ from geventhttpclient.pool import HTTPClientPool
response
✓ from geventhttpclient import response

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.

import gevent from geventhttpclient import HTTPClient from gevent import monkey import logging # Crucial for gevent to work properly monkey.patch_all() # Optional: Set up basic logging to see gevent events if needed # logging.basicConfig(level=logging.INFO) def fetch_url(url): # Create a client instance for a specific host # Using httpbin.org for a public, testable endpoint client = HTTPClient.from_url(url, connection_timeout=5, network_timeout=10) try: # Make a GET request to a path relative to the client's base URL resp = client.get('/get?foo=bar') print(f"Requested: {url}/get?foo=bar") print(f"Status: {resp.status}") print(f"Headers: {resp.headers['Content-Type']}") # Read the response body. For large responses, consider resp.read(chunk_size) body = resp.read() print(f"Body snippet: {body[:100]}...") except Exception as e: print(f"Error fetching {url}: {e}") finally: # Always close the client to release resources, especially connection pool client.close() if __name__ == '__main__': # Spawn a greenlet to run the network operation non-blocking greenlet = gevent.spawn(fetch_url, 'http://httpbin.org') # Wait for the greenlet to complete greenlet.join()
Debug
Known issues
gotchagevent's `monkey.patch_all()` is essential. If not called, `geventhttpclient` will perform blocking I/O operations, defeating the purpose of gevent.
fix
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.
affects: All versions
gotchaAlways close `HTTPClient` instances explicitly (`client.close()`) or use them as context managers (`with HTTPClient(...) as client:`). Failing to do so can lead to connection leaks and resource exhaustion, especially when using connection pooling.
fix
Surround client usage with a `try...finally` block calling `client.close()` or use a `with` statement: `with HTTPClient.from_url(...) as client: ...`
affects: All versions
gotchaWhile `geventhttpclient` does not raise exceptions for HTTP error status codes (e.g., 4xx, 5xx) by default, you might also encounter an `AttributeError` if the underlying connection or request fails to produce a valid HTTP response object, resulting in an internal type (like `HTTPSocketPoolResponse`) that lacks standard attributes such as `status`.
fix
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`).
affects: All versions
gotchaReading the entire response body with `response.read()` loads it into memory. For very large responses, this can consume significant memory.
fix
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.
affects: All versions
breakingInstallation of `gevent` failed because a C compiler was not found. `gevent` requires a C compiler (e.g., gcc) to build its C extensions.
fix
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`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'geventhttpclient'
The 'geventhttpclient' library has not been installed in the Python environment where the code is being executed.
fix
pip install geventhttpclient
AttributeError: 'str' object has no attribute 'get_client'
This error typically occurs when a string (like a URL) is passed to a function or method that expects an instance of `geventhttpclient.HTTPClient` or `geventhttpclient.Session`, or when attempting to call a method like `get_client` on an object that is actually a string.
fix
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.
timeout: timed out
The HTTP request took longer than the configured `network_timeout` or `connection_timeout` of the `HTTPClient`, or a general gevent operation exceeded its allowed time.
fix
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)`.
SSLZeroReturnError
SSL Handshake failed
An issue occurred during the SSL/TLS handshake process, often due to problems with certificate validation (e.g., outdated `certifi` CA bundle), incorrect SSL options, or blocking operations interfering with gevent's non-blocking I/O during the handshake.
fix
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.
Upgrade
Version history
2.3.9latest on PyPI · released Mar 3, 2026
Audit
Dependencies
geventrequiredCore dependency for asynchronous operations.
pyopenssloptionalOptional for advanced SSL/TLS features.
ndg-httpsclientoptionalOptional for advanced SSL/TLS features (legacy Python 2 compatibility, often paired with pyopenssl).
pyasn1optionalOptional for advanced SSL/TLS features (often used by ndg-httpsclient).
Agent activity
9 hits · last 30 days
node
8
Resources