greenlet

Lightweight in-process coroutines for cooperative concurrency in Python

Library
PyPI
v3.5.5
1,838stars
Custom / Unknown

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
82/100Excellent
Development Activity92
Maintenance52
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture82
Code Quality78
Innovation70
Learning Curve55

greenlet is a C extension that provides lightweight, in-process coroutines for CPython, spun off from Stackless Python’s tasklet model. Instead of relying on the operating system or an event loop to schedule execution, greenlets are explicit micro-threads that you switch between yourself, giving precise control over when control flow moves from one unit of work to another.

Because it exposes no implicit scheduler, greenlet acts as a foundational building block rather than a full concurrency framework: higher-level libraries like gevent and eventlet use it to implement cooperative networking, and SQLAlchemy’s async extension uses it to bridge sync and async code paths.

What You Get

  • A greenlet class representing an independent, switchable execution context with its own call stack
  • Explicit switch() semantics for transferring control and passing values between greenlets
  • Support for nested generator-like control flow without Python’s native yield keyword
  • Tracing hooks (gettrace/settrace) for observing greenlet switches
  • contextvars integration so context state follows greenlet switches correctly
  • Prebuilt wheels covering CPython on Linux, macOS, and Windows across multiple architectures

Common Use Cases

  • Powering gevent’s and eventlet’s cooperative, socket-level concurrency models
  • Bridging synchronous and asynchronous code paths, as SQLAlchemy’s asyncio extension does internally
  • Implementing custom cooperative schedulers or actor-style micro-threads on top of a low-level primitive
  • Building generator-like constructs that can yield from nested function calls

Under The Hood

Architecture: greenlet’s core is a small state machine around per-greenlet C stacks. src/greenlet/greenlet.cpp and the TGreenlet*/TMainGreenlet/TUserGreenlet files implement stack allocation, saving/restoring, and the actual switch() transfer of control via platform-specific assembly in slp_platformselect.h and the platform/ directory; PyGreenlet.cpp wraps this machinery as the Python-visible greenlet type. There is no scheduler anywhere in the codebase — every switch is caller-initiated, which is what lets libraries like gevent build their own event loops on top without fighting an existing one.

Tech Stack: Implemented as a CPython C/C++ extension (about 52% C++, 12% C) with a thin Python layer (src/greenlet/__init__.py) re-exporting the compiled _greenlet module’s symbols. Built via setuptools/pyproject.toml, with per-platform assembly stubs to handle stack switching correctly across x86, x86-64, ARM, and other architectures, plus manylinux/macOS/Windows wheel builds in CI.

Code Quality: The src/greenlet/tests/ directory contains over 5,300 lines of tests, including dedicated fail_*.py scripts that exercise crash and error-recovery paths (e.g. fail_switch_three_greenlets.py, fail_cpp_exception.py), plus test_contextvars.py, test_gc.py, and test_interpreter_shutdown.py covering edge cases like garbage collection interaction and interpreter teardown — reflecting the project’s long history of hardening against subtle stack-corruption bugs.

API Design: The public surface is deliberately minimal — greenlet(fn), .switch(*args), getcurrent(), and a couple of tracing hooks — which keeps the primitive easy to wrap but means correct usage (avoiding orphaned greenlets, understanding exception propagation across switches) requires reading the docs rather than guessing from the API shape alone.

Used by 16 apps in this directory

Python
66%
Apache 2.0

Agent Control

AI Agents

295

An open-source runtime control plane for AI agents — define safety guardrails once, apply them across agents built on LangChain, CrewAI, Google ADK, or AWS Strands, and update controls without redeploying code.

View details
79
Repo Health
71
Technical
70
Dependency
Built with
Python66%
TypeScript33%
Updated yesterday
Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

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
66
Dependency
Built with
Python90%
Updated today
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,081

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
63
Dependency
Built with
Python59%
Jupyter Notebook21%
Updated 2 days ago
Python
79%
Apache 2.0

changedetection.io

Monitoring

33,241

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

View details
90
Repo Health
80
Technical
69
Dependency
Built with
Python79%
Updated 3 days ago
Python
44%
MIT

/dev/push

Developer Tools · Devops

4,742

Self-hosted, open-source Vercel alternative that deploys Python, Node.js, PHP, and any Docker-compatible app from a Git push, with zero-downtime rollouts and real-time logs.

View details
44
Repo Health
68
Technical
73
Dependency
Built with
Python44%
HTML31%
CSS17%
Updated 5 months ago
TypeScript
51%
AGPL 3.0

Glean

Knowledge Management · Bookmarks Archiving

853

Self-hosted RSS reader and personal knowledge management tool with MCP server integration for AI assistant connectivity.

View details
78
Repo Health
75
Technical
69
Dependency
Built with
TypeScript51%
Python45%
Updated 2 days ago
Python
63%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,039

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
88
Repo Health
91
Technical
64
Dependency
Built with
Python63%
TypeScript23%
Updated 1 months ago
Python
83%
Apache 2.0

knowhere

AI Development · Developer Tools

2,515

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

View details
83
Repo Health
75
Technical
70
Dependency
Built with
Python83%
HTML16%
Updated today

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