{"library":"backports-asyncio-runner","title":"Backports Asyncio Runner","description":"Backport of Python 3.11's `asyncio.Runner`, a context manager that simplifies managing the asyncio event loop lifecycle for Python versions 3.8, 3.9, and 3.10. It provides full compatibility with Python 3.11 `asyncio.Runner` features, including contextvars support. Version 1.2.0 is current, with recent releases indicating an active maintenance cadence.","status":"active","version":"1.2.0","language":"en","source_language":"en","source_url":"https://github.com/samypr100/backports.asyncio.runner","tags":["asyncio","backport","python3","runner","context-manager"],"install":[{"cmd":"pip install backports-asyncio-runner","lang":"bash","label":"Install for supported Python versions"},{"cmd":"pip install 'backports-asyncio-runner; python_version < \"3.11\"'","lang":"bash","label":"Recommended conditional install"}],"dependencies":[{"reason":"This library is a backport specifically for these Python versions; it is not needed and should not be used on Python 3.11 or newer.","package":"Python 3.8, 3.9, or 3.10","optional":false}],"imports":[{"note":"The native `asyncio.Runner` is only available in Python 3.11+. For supported older versions (3.8-3.10), use the backport's import path. It's often recommended to use a conditional import based on `sys.version_info`.","wrong":"from asyncio import Runner","symbol":"Runner","correct":"from backports.asyncio.runner import Runner"}],"quickstart":{"code":"import sys\n\nif sys.version_info < (3, 11):\n    from backports.asyncio.runner import Runner\nelse:\n    from asyncio import Runner\n\nasync def echo(msg: str) -> None:\n    print(f\"Hello {msg}\")\n\nwith Runner() as runner:\n    runner.run(echo(\"World\"))\n\n# To use with uvloop (if installed):\n# import uvloop\n# with Runner(loop_factory=uvloop.new_event_loop) as runner:\n#     runner.run(echo(\"UVLoop World\"))","lang":"python","description":"This example demonstrates the basic usage of `Runner` as a context manager to execute an asynchronous coroutine. It includes a conditional import to ensure compatibility across Python versions where `Runner` might be native or a backport."},"warnings":[{"fix":"Ensure installation is guarded by `python_version < '3.11'` markers or simply avoid installing on Python 3.11+.","message":"This backport is intended *only* for Python versions 3.8, 3.9, and 3.10. Users of Python 3.11 or above should use the native `asyncio.Runner` from the standard library directly and should *not* install this package.","severity":"breaking","affected_versions":"<3.11 (if incorrectly installed on 3.11+)"},{"fix":"Be aware of this internal difference; if type checking `asyncio.Task` or `asyncio.Future` is critical, consider testing the specific behavior in your environment or refactoring to avoid strict type checks against the base `asyncio.Task`/`Future` type when tasks are managed by `backports.asyncio.runner`.","message":"The backport uses `asyncio.tasks._PyTask` instead of `asyncio.tasks._CTask` internally to support `asyncio.Runner` requirements. This can lead to unexpected behavior or `False` results when checking `isinstance(some_task, asyncio.Task)` or `isinstance(some_future, asyncio.Future)`, as `asyncio.Task` might default to `_CTask` elsewhere.","severity":"gotcha","affected_versions":"3.8, 3.9, 3.10"},{"fix":"This is an inherent limitation of the backport. For maximum asyncio performance, upgrading to Python 3.11 or newer is recommended.","message":"There is a slight performance degradation when using this backported `asyncio.Runner` implementation compared to the native Python 3.11 or above version. This is due to the lack of a `_CTask` backport.","severity":"gotcha","affected_versions":"3.8, 3.9, 3.10"},{"fix":"Use `pip install 'backports-asyncio-runner; python_version < \"3.11\"'` or `install_requires=['backports-asyncio-runner; python_version < \"3.11\"']`.","message":"It's recommended to include a Python version marker (e.g., `python_version < '3.11'`) in your installation commands or `install_requires` to prevent accidental installation of this backport on Python 3.11 or later environments.","severity":"gotcha","affected_versions":"* (potential incorrect installation on 3.11+)"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}