txaio provides a compatibility API between Python's asyncio and Twisted frameworks, allowing developers to write backend-agnostic asynchronous code. It is currently at version 25.12.2 and sees active development with regular releases, often preceded by nightly builds.
pip install txaioVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `txaio` with the `asyncio` backend, set up logging, and define a simple asynchronous function using the `@txaio.with_config` decorator to make it backend-agnostic. The function then uses `txaio.sleep` and a `txaio` logger, and is run using `asyncio.run()`.
Ensure `txaio.use_asyncio()` or `txaio.use_twisted()` is the first `txaio` function called in your application's entry point.
Update calls to `txaio.create_future` to `txaio.create_defer` and `txaio.is_future` to `txaio.is_defer` when working with the Twisted backend.
Decide on a single backend (asyncio or Twisted) for your `txaio`-managed code and initialize `txaio` accordingly. Avoid attempts to dynamically switch or mix `txaio` backends within the same runtime context.