skillfed

greenback

Reenter an async event loop from synchronous code

greenback v1.3.0 9.6M downloads/30d#1,520 on PyPI92
Permissive license MIT -or- Apache License 2.0 Active released

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 greenback

uv

uv add greenback

poetry

poetry add greenback

Installing 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

Development Status :: 4 - BetaFramework :: AsyncIOFramework :: TrioLicense :: OSI Approved :: Apache Software LicenseLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

call async from sync codeasyncio sync bridgeevent loop reentryasync await from synchronous functiongreenlet async interopmigrate to async incrementallysync wrapper for async code
async-migrationgreenlet-basedevent-loop-interop

More Application Frameworks packages