--- id: aiocontextvars version: "0.2.2" license: BSD license license_treatment: permissive maintenance: abandoned --- # aiocontextvars — Asyncio support for PEP-567 contextvars backport. License: permissive · Maintenance: abandoned · Downloads: 446.2K/mo ## What it is and what it does aiocontextvars patches the contextvars backport library to add asyncio support for Python 3.5 and 3.6, allowing context variables to be properly inherited and maintained across async task boundaries. On Python 3.7+, it is simply a pass-through to the built-in contextvars module, which already has full asyncio integration. The package works by monkey-patching asyncio's event loop and task creation to attach and propagate copied contexts. It requires importing the module before creating any event loops or tasks to ensure the patches are applied. On older Python versions, it provides a workaround for the lack of native context parameter support in call_soon() and Task creation, though the implementation differs from Python 3.7's native approach. Use it for: - Maintaining request-scoped context (e.g., user ID, request ID) across async task chains on Python 3.5–3.6. - Migrating legacy asyncio code from Python 3.5–3.6 that relies on context variable inheritance to Python 3.7+. - Ensuring context isolation between concurrent tasks in older Python versions before native contextvars asyncio support existed. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides asyncio support for the contextvars backport library on Python 3.5 and 3.6, and delegates to the built-in contextvars module on Python 3.7+. No, unless you are maintaining legacy code on Python 3.5 or 3.6 that requires contextvars asyncio support. The package is abandoned (last release 2019, last commit 2022) and unnecessary on Python 3.7+. Modern Python versions have built-in contextvars with full asyncio support; use the standard library instead. ## Install pip install aiocontextvars uv add aiocontextvars poetry add aiocontextvars ## Installing aiocontextvars Before you install: Low install friction with a single pure-Python dependency. However, the package is abandoned—last release was in 2019 and last commit in 2022. On Python 3.7+, it is purely a delegate to the built-in contextvars module, making it unnecessary for modern codebases. License in practice: BSD license is permissive and imposes no significant restrictions on use or redistribution. Quickstart: pip install aiocontextvars import aiocontextvars import asyncio from contextvars import ContextVar var = ContextVar('var') var.set('value') async def main(): print(var.get()) asyncio.run(main()) On Python 3.5 and 3.6, must import aiocontextvars before creating event loops or tasks; custom event loop implementations (e.g., uvloop.new_event_loop) will not be patched and won't behave correctly. Verify before relying: - Whether the package still works reliably with modern asyncio implementations given its age and abandonment status. - Whether the contextvars asyncio backport issue mentioned in the description has since been resolved in the upstream contextvars package. ## Package facts - License: BSD license (permissive) - Python support: supports_current - Install friction: low - Maintenance: abandoned - Downloads: 446.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags contextvars asyncio support, context variables async tasks, asyncio context propagation, PEP-567 backport asyncio, task-local context storage, async context inheritance, async-context, legacy-python [View on SkillFed](https://skillfed.io/packages/aiocontextvars) · [View on PyPI](https://pypi.org/project/aiocontextvars/)