skillfed

contextvars

PEP 567 Backport

contextvars v2.4 1.4M downloads/30d#3,954 on PyPI90
Permissive license Apache License, Version 2.0 Abandoned released

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 contextvars

uv

uv add contextvars

poetry

poetry add contextvars

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.5Programming Language :: Python :: 3.6

Tags

context variables python 3.6PEP 567 backportcontextvars backportcontext-local state managementasync context variablesthread-local alternatives
backportdeprecatedpython-3.6-only

More Software Development packages