Contextvars are a concept similar to thread-local variables, intended to provide value isolation across co-routines executed in parallel in a Python async application. They are implemented in a module with the same name introduced in the stdlib in Python 3.7.0, specified in PEP-567.
Python-contextvars were first justified and introduced in PEP-550, which ended-up being rejected mainly for holding a too-ambitious scope. A narrowed down proposal came in PEP-567 that ended up implemented in Python 3.7.0. The idea is to be able to have cross-local scope values that can be shared across co-routines running in the same task under async-io, in the same way that thread-local-storage variables can provide value isolation for variable-names across different threads.
PEP 550 presents context vars as:
This PEP adds a new generic mechanism of ensuring consistent access to non-local state in the context of out-of-order execution, such as in Python generators and coroutines.
Thread-local storage, such as threading.local(), is inadequate for programs that execute concurrently in the same OS thread. This PEP proposes a solution to this problem.