unsync

raw JSON →
1.4.0 verified Fri May 01 auth: no python

unsync is a decorator-based library that bridges synchronous and asynchronous Python code. It allows you to call async functions from sync code and vice versa without manually managing event loops. Current version is 1.4.0. Release cadence is low; last release was in 2020.

pip install unsync
error RuntimeError: There is no current event loop in thread 'MainThread'.
cause Calling an unsync-decorated function from a context where no event loop is running.
fix
Ensure there is a running event loop, or use asyncio.run() or unsync's own setup if in a synchronous context.
error AttributeError: module 'unsync' has no attribute 'unsync'
cause Importing unsync with 'import unsync' instead of 'from unsync import unsync'.
fix
Use 'from unsync import unsync' to import the decorator.
gotcha Using @unsync in an async context (e.g., inside another async function) may cause unexpected behavior; prefer direct await.
fix Use await directly when already in an async function instead of @unsync.
gotcha The unsync decorator returns a future-like object, not the immediate result; you must call .result() or iterate accordingly.
fix Call .result() on the returned object to get the value (e.g., async_function().result()).
gotcha Global event loops can cause issues if multiple event loops are created, especially in test suites.
fix Use asyncio.run() for top-level async calls instead of relying on unsync's loop management.

Decorate an async function with @unsync to call it from synchronous code; the decorated function returns a concurrent.futures.Future or similar object.

from unsync import unsync
import asyncio

@unsync
async def async_function():
    await asyncio.sleep(0.1)
    return "Hello from async"

result = async_function()
print(result)