--- id: greenback version: "1.3.0" license: MIT -or- Apache License 2.0 license_treatment: permissive maintenance: active --- # greenback — Reenter an async event loop from synchronous code License: permissive · Maintenance: active · Downloads: 9.6M/mo ## 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 above — 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 pip install greenback uv add greenback 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_current - Install friction: low - Maintenance: active - Downloads: 9.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags call async from sync code, asyncio sync bridge, event loop reentry, async await from synchronous function, greenlet async interop, migrate to async incrementally, sync wrapper for async code, async-migration, greenlet-based, event-loop-interop [View on SkillFed](https://skillfed.io/packages/greenback) · [View on PyPI](https://pypi.org/project/greenback/)