greenback
Reenter an async event loop from synchronous code
What it is and what it does
Greenback solves the problem of incrementally migrating a synchronous codebase to async/await syntax. When you port code to asyncio or Trio, you typically must convert every function in the call chain to async, even if most of them don't perform I/O themselves. Greenback lets you call async functions from synchronous code, as long as that sync code was originally invoked from an async task that set up a greenback portal.
It works by running your async task inside a greenlet, then using greenlet's context-switching to jump back to the parent greenlet (which has direct access to the event loop) when you call greenback.await_(). The result or exception from the async call is then returned to the task greenlet. The library is pure Python on top of the mature greenlet C module, with minimal overhead.
Use it for:
- Incrementally port a large codebase to async/await one layer at a time, leaving middle-layer functions unchanged.
- Interoperate with existing libraries that don't support async without spawning threads or rewriting their internals.
- Design async APIs that need to block in places where await syntax is forbidden, such as property getters.
- Call async functions from synchronous wrapper functions in a legacy codebase without full conversion.
- Bridge between synchronous and asynchronous code paths within the same event loop task.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Allows you to call async functions from synchronous code that runs within an asyncio or Trio event loop, bridging the gap between sync and async codebases without threading.
Yes, if you need to migrate existing sync code to async incrementally or interoperate with non-async libraries without threading. The library is actively maintained, has no known vulnerabilities, low install friction, and is permissively licensed. The main trade-off is a small performance cost per task and the requirement that C extensions used alongside greenback must be well-behaved. For greenfield async projects, it's unnecessary; for bridging sync and async, it's a solid choice.
Install
greenback on PyPI
pip
pip install greenbackuv
uv add greenbackpoetry
poetry add greenbackInstalling greenback
Before you install
Low friction: pure Python wheel with only three runtime dependencies (greenlet, sniffio, outcome). Actively maintained as of 2026-02-17 with 92 repository stars. Requires Python 3.8 or later and greenlet support (CPython and PyPy both work).
License in practice
Dual-licensed under MIT or Apache 2.0 (permissive). You may choose either license for your use, giving flexibility for both proprietary and open-source projects.
Quickstart
import greenback
async def main():
await greenback.ensure_portal()
result = greenback.await_(some_async_function())
await main()
Requires Python 3.8+. Greenlet must be available; works on CPython and PyPy but not other implementations. Poorly-behaved C extensions may crash when used with greenback.
Verify before relying
- Whether the minor performance impact of running tasks inside a greenlet is acceptable for your specific workload.
- Compatibility with C extension modules in your dependency tree—greenback may expose latent bugs in extensions that violate greenlet's assumptions about heap allocation.
- Whether greenback.await_() works reliably with all async frameworks beyond asyncio and Trio.
Package facts
| License | MIT -or- Apache License 2.0 (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — greenlet, sniffio, outcome |
| Maintenance | actively maintained — 234 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 9,609,038/month — #1,520 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: greenback-1.3.0-py3-none-any.whl
Keywords: async, io, trio, asyncio
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
greenletGreenlet provides lightweight coroutines for…
permissive · top 100 on PyPI
async_generatorProvides async generators and async context…
permissive · top 5,000 on PyPI
duetDuet is a lightweight async library that wraps…
permissive · top 15,000 on PyPI
geventgevent provides lightweight concurrent…
permissive · top 1,000 on PyPI
threadloopRuns Tornado coroutines from synchronous Python…
permissive · top 15,000 on PyPI
asyncguiAsyncGui provides structured concurrency…
permissive · top 15,000 on PyPI
sniffioDetects which async library (asyncio, Trio,…
permissive · top 100 on PyPI
synchronicityWraps async functions, generators, and classes…
permissive · top 1,000 on PyPI
asyncerAsyncer provides utility functions for working…
permissive · top 5,000 on PyPI
culsansProvides a dual-interface queue (sync and…
permissive · top 5,000 on PyPI