Syncer is a Python library designed to simplify the conversion of asynchronous functions to synchronous ones. It abstracts away the boilerplate of `asyncio.get_event_loop().run_until_complete()`, making it easier to call `async def` functions from synchronous contexts, particularly useful in testing or when integrating with synchronous codebases. The current version is 2.0.3, with releases occurring periodically to maintain compatibility and add features.
pip install syncerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the primary ways to use `syncer.sync`. It can convert an `async def` function into a synchronous callable, directly execute a coroutine object to retrieve its result, or be used as a decorator on `async def` test methods to run them in a synchronous test runner.
Ensure `syncer.sync` is called from a truly synchronous execution point, typically the top-level of a script or a synchronous test method, not nested within another active asynchronous function call stack.
For blocking I/O within async functions, consider using `asyncio.to_thread()` to run the blocking operation in a separate thread, preventing it from stalling the event loop, even when the async function is then run via `syncer.sync`.
Always ensure you are passing either the async function (to get a synchronous wrapper) or the coroutine (to get its result) as intended. The quickstart examples illustrate both patterns clearly.
No dependency data recorded yet.