contextvars
PEP 567 Backport
What it is and what it does
This package backports Python 3.7's contextvars module to Python 3.6, implementing PEP 567 context-local state. It allows you to create and manage context variables that maintain separate values across concurrent execution contexts—useful in async code and thread pools where thread-local storage is insufficient.
The package is now largely obsolete: Python 3.7+ includes contextvars in the standard library, and the package itself has been abandoned since its last release on 2019-04-01 with no active maintenance. It exists primarily as a compatibility shim for legacy Python 3.6 codebases. The standard library always takes precedence, so listing it as a dependency is safe but unnecessary for modern projects.
Use it for:
- Maintaining request-scoped state in async frameworks running on Python 3.6.
- Passing context through concurrent.futures thread pools without global variables.
- Porting code that uses contextvars from Python 3.7+ down to Python 3.6 environments.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides the PEP 567 contextvars module for Python 3.6, enabling context-local state management in concurrent code.
No. If you are on Python 3.7 or later, use the standard library contextvars. If you must support Python 3.6, this backport is your only option, but the lack of maintenance since 2019-04-01 and high install friction make it a last resort. Modern projects should not depend on this.
Install
contextvars on PyPI
pip
pip install contextvarsuv
uv add contextvarspoetry
poetry add contextvarsInstalling contextvars
Before you install
High install friction due to source distribution. Package is abandoned as of 2019 with no maintenance since its last release. Modern Python versions include contextvars in the standard library, making this backport obsolete for most use cases.
License in practice
Licensed under Apache License, Version 2.0 (permissive). No restrictions on commercial or private use; attribution required.
Quickstart
pip install contextvars
import contextvars
my_var = contextvars.ContextVar('my_var')
my_var.set('value')
Python 3.6 only; Python 3.7+ includes contextvars in the standard library and will use that instead of this backport.
Verify before relying
- Whether asyncio event loop support was ever added after the 2019 release note stating it was not yet available.
- Compatibility with Python 3.5 (listed in classifiers) despite the description stating Python 3.6 support.
- Current status of Python 3.6 support lifecycle and whether this backport remains usable.
Package facts
| License | Apache License, Version 2.0 (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,692 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,399,193/month — #3,954 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: contextvars-2.4.tar.gz
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
aiocontextvarsProvides asyncio support for the contextvars…
permissive · top 15,000 on PyPI
opencensus-contextProvides in-process context propagation for…
permissive · top 1,000 on PyPI
types-contextvarsProvides type stubs for Python's contextvars…
permissive · top 15,000 on PyPI
pickle5Backports the pickle 5 protocol (PEP 574) and…
permissive · top 15,000 on PyPI
backports.zoneinfoProvides IANA time zone support for Python…
permissive · top 5,000 on PyPI
futuresBackport of Python 3's concurrent.futures…
permissive · top 5,000 on PyPI
dataclassesProvides the PEP 557 dataclasses module for…
permissive · top 5,000 on PyPI
eval-type-backportEnables newer Python typing syntax (like `X |…
permissive · top 1,000 on PyPI
asyncioThis package is an obsolete backport of…
permissive · top 1,000 on PyPI
contextlib2contextlib2 backports the Python standard…
permissive · top 5,000 on PyPI