Install & Compatibility
Where this runs
tested against v26.8.0.20260811 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
gevent-stubs
✓ import gevent_stubs
✗ import gevent-stubs
This example demonstrates how types-gevent provides type hints for the gevent library. After installing both 'gevent' and 'types-gevent', a type checker like MyPy can analyze the code. The type hints for `fetch_data` and `process_urls` will be checked, and `gevent.spawn` and `gevent.joinall` will have their expected types available for static analysis.
import gevent
import gevent.monkey
import typing
gevent.monkey.patch_all()
def fetch_data(url: str) -> str:
"""Simulates fetching data asynchronously."""
gevent.sleep(0.1) # Simulate I/O delay
return f"Data from {url}"
def process_urls(urls: typing.List[str]) -> typing.List[str]:
greenlets = [gevent.spawn(fetch_data, url) for url in urls]
gevent.joinall(greenlets)
results = [g.value for g in greenlets]
return results
if __name__ == "__main__":
urls_to_process = ["http://example.com/1", "http://example.com/2"]
processed_data = process_urls(urls_to_process)
print(f"Processed: {processed_data}")
# To run type checking, save this as e.g., 'main.py' and run:
# mypy main.py
Debug
Known issues
breakingType stubs are version-specific. Installing 'types-gevent' for 'gevent==X.Y' alongside a different version of 'gevent' (e.g., 'gevent==A.B' where A.B != X.Y) can lead to incorrect type checking errors or missed type issues. The 'types-gevent' package version `X.Y.Z.YYYYMMDD` indicates it targets `gevent==X.Y.*`.fixEnsure that the major and minor version numbers of `types-gevent` (e.g., '25.9' from '25.9.0.20260408') match or are compatible with your installed `gevent` runtime version. Pin both `gevent` and `types-gevent` to compatible versions in your project's dependencies.
affects: All versions
gotchaStub packages like 'types-gevent' provide static type information only; they do not include any runtime code or functionality. Installing 'types-gevent' without the actual 'gevent' library will not make 'gevent' available for execution.fixAlways install the 'gevent' runtime library (`pip install gevent`) in addition to its type stubs (`pip install types-gevent`) for your application to function correctly.
affects: All versions
gotchaWhen using `gevent.monkey.patch_all()`, the patching must occur as early as possible in your application's lifecycle, typically at the very beginning of your main script. Delaying patching, especially after other standard library modules (e.g., `concurrent.futures`, `threading`) have been imported, can result in those modules retaining their original blocking behavior or lead to conflicts.fixPlace `gevent.monkey.patch_all()` at the top of your application's entry point file before any other imports that might use standard library I/O or concurrency primitives.
affects: All versions of gevent utilizing monkey patching
gotchaGevent is designed for I/O-bound concurrency, not CPU-bound parallelism. Running CPU-intensive tasks within a greenlet will block the entire event loop, preventing other greenlets from executing and negating the benefits of cooperative multitasking.fixOffload CPU-intensive operations to separate processes or threads (e.g., using `multiprocessing` or `concurrent.futures.ThreadPoolExecutor` where appropriate) to avoid blocking the gevent event loop.
affects: All versions
gotchaCombining `gevent` with Python's built-in `multiprocessing` module can introduce complex issues and is generally discouraged without careful management. Specifically, after forking on POSIX systems, `gevent`'s internal state in the child process can be ill-posed, leading to unexpected behavior.fixIf multiprocessing is necessary, carefully review the `gevent` documentation on `gevent.subprocess` and `multiprocessing` interactions. Consider using process pools or alternative strategies for multi-core utilization that are compatible with `gevent`'s cooperative concurrency model.
affects: All versions
Upgrade
Version history
26.8.0.20260811latest on PyPI · released Aug 11, 2026
Audit
Dependencies
geventrequiredtypes-gevent provides type hints for the gevent library; gevent is required at runtime for any practical use of the stubs.