Python ContextVars Module
Context variables for async — ContextVar, copy_context, Context. This category documents 5 Python contextvars module entries, and each page gives you the full syntax, the parameter list, the return value, and a runnable example. The entries include: contextvars.ContextVar(), ContextVar.get(), ContextVar.set(), ContextVar.reset(), contextvars.copy_context(). contextvars.ContextVar() creates a context variable that has separate values in different async contexts. ContextVar.get() returns the value of the context variable for the current context. ContextVar.set() sets the value of the context variable for the current context. ContextVar.reset() resets the context variable to its previous value using the token from set(). contextvars.copy_context() returns a copy of the current context (all context variables and their values). ContextVars Module belongs to the Dev Tools group alongside Inspect Module, Pdb Module, Traceback Module, Timeit Module. You can also search across every category from the search page, browse the complete A–Z index, or try any example in the Python playground.