{"id":1801,"library":"asyncer","title":"Asyncer","description":"Asyncer is a small Python library built on top of AnyIO, focused on improving developer experience when working with `async` and `await` and mixing async with regular blocking code. It provides utility functions like `asyncify` and `syncify` to bridge asynchronous and synchronous code more conveniently, offering better editor support and type checking. It is actively maintained, with frequent minor releases.","status":"active","version":"0.0.17","language":"en","source_language":"en","source_url":"https://github.com/fastapi/asyncer","tags":["async","await","concurrency","anyio"],"install":[{"cmd":"pip install asyncer","lang":"bash","label":"Install Asyncer"}],"dependencies":[{"reason":"Core asynchronous backend library that Asyncer is built upon for concurrent execution.","package":"anyio"},{"reason":"Used for detecting the current asynchronous backend in use (e.g., asyncio, Trio).","package":"sniffio"},{"reason":"Provides backported typing features for older Python versions. Required for Python < 3.15.","package":"typing_extensions","optional":true}],"imports":[{"note":"Used to call synchronous (blocking) functions from an asynchronous context without blocking the event loop.","symbol":"asyncify","correct":"from asyncer import asyncify"},{"note":"Used to call asynchronous functions from a synchronous context.","symbol":"syncify","correct":"from asyncer import syncify"}],"quickstart":{"code":"import anyio\nfrom asyncer import asyncify\nimport time\n\ndef blocking_function(name: str) -> str:\n    \"\"\"A blocking function that simulates work.\"\"\"\n    time.sleep(0.1)  # Simulate I/O or CPU-bound work\n    return f\"Hello from blocking func, {name}!\"\n\nasync def main():\n    print(\"Starting async main function.\")\n    # Run a blocking function in a worker thread using asyncify\n    message = await asyncify(blocking_function)(name=\"World\")\n    print(message)\n    print(\"Finished async main function.\")\n\nif __name__ == \"__main__\":\n    anyio.run(main)","lang":"python","description":"This example demonstrates how to use `asyncer.asyncify` to call a regular blocking function (`blocking_function`) from within an asynchronous context (`main`). `asyncify` ensures the blocking operation runs in a worker thread, preventing it from blocking the main event loop. The `anyio.run(main)` call starts the AnyIO event loop to execute the asynchronous `main` function."},"warnings":[{"fix":"Upgrade to Python 3.10 or higher, or pin Asyncer to `<0.0.15`.","message":"Asyncer dropped support for Python 3.9 in version 0.0.15. Projects requiring Python 3.9 or older must use an earlier Asyncer version.","severity":"breaking","affected_versions":">=0.0.15"},{"fix":"Upgrade to Python 3.9 or higher (preferably 3.10+), or pin Asyncer to `<0.0.12`.","message":"Asyncer dropped support for Python 3.8 in version 0.0.12. Projects requiring Python 3.8 or older must use an earlier Asyncer version.","severity":"breaking","affected_versions":">=0.0.12"},{"fix":"Replace `asyncify(..., cancellable=True)` with `asyncify(..., abandon_on_cancel=True)`. Refer to AnyIO documentation for precise behavior of `abandon_on_cancel`.","message":"The `cancellable` argument for `asyncify()` was refactored and is now `abandon_on_cancel`. Using `cancellable=True` might not have the intended effect or could lead to future breakage.","severity":"deprecated","affected_versions":">=0.0.8"},{"fix":"Ensure `asyncer` functions are used within an appropriate asynchronous context (e.g., `anyio.run()`) or explicitly handle synchronous execution with `syncify(..., raise_sync_error=False)`.","message":"Asyncer functions, particularly `syncify`, expect to be called either from an existing asynchronous event loop (e.g., within an `async` function running via `anyio.run()` or `asyncio.run()`) or from a worker thread initiated by `asyncify`. Calling `syncify()` directly in a purely synchronous top-level context may implicitly start a new event loop or raise an error if `raise_sync_error` is not set to `False`.","severity":"gotcha","affected_versions":"All"},{"fix":"Pin the Asyncer version in your `requirements.txt` or `pyproject.toml` (e.g., `asyncer==0.0.17`) and maintain comprehensive tests to ensure compatibility when upgrading.","message":"The Asyncer documentation recommends pinning the exact version of the library due to its small size and potential for future changes, and always having tests for your project.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}