Synchronicity is a Python library designed to simplify the development of libraries that need to offer both synchronous (blocking) and asynchronous (non-blocking) APIs from a single async implementation. It achieves this by creating an event loop on a separate thread, wrapping functions, generators, and classes, allowing them to be called synchronously or asynchronously via a `.aio` attribute. The current version is 0.12.1, and it appears to be actively maintained with regular updates.
pip install synchronicityVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define an asynchronous function and then use `Synchronizer` to expose both a synchronous (blocking) interface and an asynchronous (`.aio`) interface for it. The synchronous call blocks until completion, while the asynchronous call can be awaited within an async context.
Access class attributes via getter methods or `@property` decorators on the original (unwrapped) class definition.
Ensure all I/O-bound or long-running operations within your original async functions are truly asynchronous (e.g., use `await` with async-compatible libraries like `aiohttp` instead of `requests`).
Be mindful of this overhead for extremely performance-sensitive, CPU-bound tasks where thread isolation isn't strictly necessary. Profile your application to understand performance implications.
Separate your wrapper and implementation code into different modules. Use the `python -m synchronicity.type_stubs` tool to generate `.pyi` files for your 'wrapper modules' to provide static type support.
If you need to synchronize a context manager, define it as a class and apply `@synchronizer.wrap` to the class, or use `@synchronizer.asynccontextmanager` for async context manager functions.
No dependency data recorded yet.