greenlet

3.3.2 · active · verified Sat Mar 28

greenlet is a Python package that provides lightweight in-process concurrent programming through micro-threads called 'greenlets'. The current version is 3.3.2, released on February 20, 2026. The library has a stable release cadence, with updates addressing compatibility and performance improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates creating and switching between two greenlets. 'gr1' starts 'test1', which switches to 'gr2' running 'test2', and then switches back to 'gr1'.

from greenlet import greenlet

def test1():
    print("[gr1] main  -> test1")
    gr2.switch()
    print("[gr1] test1 <- test2")
    return 'test1 done'

def test2():
    print("[gr2] test1 -> test2")
    gr1.switch()

gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr1.switch()

view raw JSON →