gevent

Coroutine-based concurrency for Python, built on greenlets and a fast libev/libuv event loop.

Library
PyPI
v26.8.0
6,447stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity80
Maintenance72
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture88
Code Quality85
Innovation82
Learning Curve80

gevent is a networking and concurrency library for Python that lets you write code in a normal, synchronous style while it runs cooperatively under the hood. Instead of callbacks or explicit async/await, gevent uses greenlets — lightweight, cooperatively-scheduled coroutines — switched by a C-speed event loop (libev on POSIX systems, libuv everywhere including Windows) so thousands of concurrent sockets can be handled without the overhead of OS threads.

Its most distinctive feature is monkey patching: calling gevent.monkey.patch_all() early in a program rewrites the standard library’s blocking primitives (socket, ssl, threading, subprocess, select, time.sleep, and more) so ordinary code — including third-party libraries never written with gevent in mind — becomes cooperative without any rewrite. This has made gevent a long-standing backbone for WSGI servers (gevent.pywsgi), job queues, and any Python service that needs to hold open large numbers of slow connections.

The project has been maintained continuously since 2009, first by Denis Bilenko and, since version 1.1, by Jason Madden with backing from NextThought and Institutional Shareholder Services. Its core primitives (Greenlet, Pool, Queue, Event, Timeout, AsyncResult) deliberately mirror Python’s standard library APIs (threading, queue), so developers already familiar with threaded Python can adopt it with a small learning curve while sidestepping the GIL contention and per-thread memory cost of real OS threads.

What You Get

  • Cooperative greenlets — lightweight, stack-switched coroutines scheduled by gevent.spawn/gevent.joinall, far cheaper than OS threads
  • A monkey-patching layer (gevent.monkey.patch_all) that makes unmodified standard-library code and third-party packages cooperative automatically
  • Cooperative sockets and SSL support for building non-blocking TCP/UDP clients and servers with familiar socket-module semantics
  • Built-in WSGI/HTTP server (gevent.pywsgi) and a StreamServer/DatagramServer base for building custom network servers
  • A gevent.subprocess module and threadpool (gevent.threadpool) for integrating blocking or CPU-bound work into a cooperative program
  • Synchronization primitives that mirror the standard library — Event, Semaphore, Lock, Queue, Timeout — for coordinating greenlets
  • Pluggable DNS resolution (threadpool, c-ares, or dnspython) so hostname lookups don’t block the event loop
  • An event/plugin system (gevent.events) that fires hooks before and after monkey patching for observability and customization

Common Use Cases

  • Running a WSGI application server (via gevent.pywsgi or gunicorn’s gevent worker) that needs to hold open thousands of slow HTTP/WebSocket connections
  • Retrofitting an existing synchronous codebase or third-party library with concurrency by monkey-patching instead of rewriting it around async/await
  • Building custom TCP/UDP network services — proxies, chat servers, port forwarders — using StreamServer/DatagramServer
  • Fan-out I/O-bound work (many parallel HTTP calls, DNS lookups, or DB queries) with a gevent.pool.Pool instead of managing a thread pool by hand
  • Running background job workers or task queues that need high connection concurrency without the memory cost of one OS thread per job

Under The Hood

Architecture gevent is layered around a single-threaded event loop hub (gevent.hub.Hub, in src/gevent/hub.py) that wraps a libev or libuv reactor and drives raw greenlet.greenlet objects switched via gevent._greenlet_primitives and gevent._hub_primitives. User-facing Greenlet objects (src/gevent/greenlet.py) wrap the raw greenlet with linking, exception propagation, and result tracking, while low-level waiting is centralized in gevent._waiter.Waiter and gevent.timeout.Timeout so every blocking primitive (Queue, Event, Semaphore, sockets) composes on the same wait/switch mechanism instead of reimplementing it. Cooperative sockets (gevent/socket.py, gevent/_socket3.py) and the WSGI server (gevent/pywsgi.py) sit on top of this hub, and monkey patching (gevent/monkey/__init__.py) works by replacing standard-library module attributes at runtime with these hub-aware equivalents — a design that lets unmodified third-party code become cooperative purely through import-time substitution. What breaks if this abstraction changes: every cooperative primitive in the codebase (sockets, queues, subprocess, threading shims) depends on the same hub/greenlet switching contract, so altering it is a global, not local, change.

Tech Stack The library is written in Python with performance-critical modules also compiled via Cython (.pyx/.pxd files alongside pure-Python fallbacks), and links against the greenlet C extension for stack switching. The event loop backend is vendored/bundled libev and libuv C libraries (see the deps/ directory), with libuv as the default, cross-platform backend and libev as a legacy option; c-ares is vendored for the optional async DNS resolver. The build system is setuptools driven through pyproject.toml and a substantial custom setup.py/_setupares.py/_setuplibev.py, since the package compiles native extensions against these bundled C libraries and against cffi on PyPy. CI runs via GitHub Actions (.github/workflows/ci.yml) and packaging targets manylinux/macOS/Windows wheels for CPython 3.9+ and PyPy 3.9+.

Code Quality The test suite is extensive — over 160 files under src/gevent/tests/, covering sockets, SSL, subprocess, threading interop, monkey-patching edge cases, and known-failure tracking per Python version/platform, run via python -m gevent.tests and orchestrated across many environments in tox.ini (CPython 3.8–3.12, PyPy3, cffi and libuv variants, plus dedicated lint and leak-detection environments). Linting is enforced with a project-specific .pylintrc, and the codebase carries decades of accumulated defensive comments around C-level greenlet/frame access and platform quirks (Windows, PyPy, free-threaded CPython), reflecting a mature project that has had to harden against many real-world edge cases rather than one written from a clean slate.

API Design gevent deliberately mirrors familiar standard-library APIs — Queue, Event, Semaphore, socket and subprocess modules — so a developer who knows threading/socket can be productive with minimal new vocabulary, and the single monkey.patch_all() call is the primary onboarding surface for adopting it in an existing codebase. The public API is extensively documented (91 reStructuredText files under docs/, published to gevent.org and readthedocs), with explicit warnings and tips embedded in docstrings (e.g., patch-order caveats, free-threading limitations) rather than left to be discovered via bug reports.

Used by 8 apps in this directory

Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,755

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python90%
Updated yesterday
Python
80%
Apache 2.0

changedetection.io

Monitoring

33,668

Self-hosted website change detection with AI-powered smart alerts, browser automation, price tracking, and 85+ notification channels.

View details
91
Repo Health
80
Technical
68
Dependency
Built with
Python80%
Updated 3 days ago
TypeScript
50%
Other

Dify

No Code Platforms · AI Development · Developer Tools

154,649

Visual LLM workflow platform with RAG pipelines, agent capabilities, and model management for building production AI applications.

View details
92
Repo Health
85
Technical
67
Dependency
Built with
TypeScript50%
Python46%
Updated yesterday
Python
85%
Apache 2.0

knowhere

AI Development · Developer Tools

2,942

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
69
Dependency
Built with
Python85%
HTML15%
Updated yesterday
Python
65%
MIT

LibrePhotos

File Storage

8,061

Self-hosted photo library with AI-powered face recognition, semantic search, and automatic event albums — no cloud required.

View details
82
Repo Health
78
Technical
66
Dependency
Built with
Python65%
TypeScript32%
Updated 2 days ago
Python
53%
Other

Odoo

ERP · CRM · Productivity

54,194

The open source ERP platform that integrates CRM, accounting, inventory, manufacturing, and 60+ business apps into one seamlessly connected suite.

View details
87
Repo Health
82
Technical
64
Dependency
Built with
Python53%
JavaScript43%
Updated today
TypeScript
94%
Other

OpenHands

AI Code Assistants · AI Development

86,377

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
70
Dependency
Built with
TypeScript94%
Updated today
Python
45%
Other

Redash

Analytics · Data Engineering

28,781

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
85
Repo Health
74
Technical
60
Dependency
Built with
Python45%
JavaScript31%
TypeScript17%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search