Eventlet
Greenlet
gevent
Python concurrency
asynchronous programming

Eventlet vs Greenlet vs gevent?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

greenlet, gevent, and Eventlet are related, but they are not interchangeable. greenlet is the low-level coroutine primitive, while gevent and Eventlet are higher-level cooperative I/O frameworks built on top of that idea. The practical choice today depends less on raw capability and more on how much legacy green-thread code you already have.

Start With greenlet: The Primitive Layer

The greenlet project describes greenlets as lightweight coroutines for in-process concurrent programming. A greenlet does not provide an event loop, network stack, or scheduler by itself. It only gives you manual control over switching execution.

python
1from greenlet import greenlet
2
3
4def first():
5    print("first: before switch")
6    gr2.switch()
7    print("first: after switch")
8
9
10def second():
11    print("second")
12    gr1.switch()
13
14
15gr1 = greenlet(first)
16gr2 = greenlet(second)
17gr1.switch()

This is powerful, but it is also very low level. You typically use greenlet directly when building frameworks or advanced control-flow machinery, not when you just want a practical networking stack.

What gevent Adds

gevent builds a cooperative concurrency framework on top of greenlets and an event loop. Its documentation describes it as a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev or libuv event loop.

That means gevent is not just "greenlet plus helpers." It adds:

  • an event loop
  • cooperative sockets and DNS
  • greenlet spawning APIs
  • synchronization primitives
  • optional monkey patching for standard-library I/O
python
1import gevent
2from gevent import socket
3
4
5def resolve(host):
6    return socket.gethostbyname(host)
7
8jobs = [gevent.spawn(resolve, host) for host in ["python.org", "example.com"]]
9gevent.joinall(jobs)
10print([job.value for job in jobs])

This is the kind of code people usually mean when they say they want green-threaded I/O in Python.

What Eventlet Adds

Eventlet occupies a similar space: cooperative networking and green threads built around non-blocking I/O. Historically it was a popular way to write concurrent network services without native async and await syntax.

python
1import eventlet
2from eventlet.green.urllib.request import urlopen
3
4
5def fetch(url):
6    return len(urlopen(url).read())
7
8pool = eventlet.GreenPool()
9for size in pool.imap(fetch, ["https://example.com", "https://python.org"]):
10    print(size)

However, current Eventlet documentation now explicitly discourages new usage. The project warns that new usages are heavily discouraged and recommends asyncio for new async network programming, while positioning Eventlet in maintenance mode with a migration path for existing users.

That changes the recommendation significantly.

Practical Differences That Matter

The easiest way to compare them is by layer:

  • 'greenlet: low-level coroutine switching primitive'
  • 'gevent: full cooperative I/O framework using greenlet'
  • Eventlet: another cooperative I/O framework using green threads, now oriented toward maintenance and migration rather than new adoption

In other words, greenlet is the foundation. gevent and Eventlet are frameworks that solve a larger problem.

gevent documentation also notes that it was inspired by Eventlet, but presents itself as having a more consistent API and simpler implementation. For teams already committed to the greenlet-based ecosystem, that makes gevent the more common modern choice between the two high-level libraries.

Which One Should You Choose

For a new Python service, the default answer should usually be asyncio, not any of these three. That is not because gevent or greenlet are broken. It is because asyncio is the standard library async model and integrates more naturally with current Python tooling.

If you are maintaining an existing greenlet-based stack:

  • choose greenlet only when you need a low-level primitive or are building infrastructure
  • choose gevent when you want a mature cooperative I/O framework in an existing greenlet-style architecture
  • keep Eventlet mainly for legacy code that already depends on it, with migration planning in mind

That is a more useful decision rule than comparing them as if they were three equal alternatives.

Common Pitfalls

The most common mistake is treating greenlet as a drop-in substitute for gevent or Eventlet. It is not. It gives you switching primitives, not a networking framework.

Another problem is recommending Eventlet for new projects without acknowledging its current maintenance stance. That advice is outdated.

Developers also often underestimate monkey patching. Both high-level frameworks can rely on cooperative replacements for blocking APIs, and that can interact badly with libraries that assume standard behavior.

Finally, do not confuse cooperative concurrency with parallel CPU execution. These libraries are strongest for I/O-bound workloads, not for CPU-bound scaling.

Summary

  • 'greenlet is the low-level coroutine primitive.'
  • 'gevent is a higher-level cooperative I/O framework built on greenlet.'
  • Eventlet is a similar framework, but its current docs discourage new usage and emphasize migration.
  • For new Python async applications, asyncio is usually the better default.
  • Use gevent or Eventlet mainly when you are working within an existing green-threaded stack.

Course illustration
Course illustration

All Rights Reserved.