Skip to main content

with-contextvars

This module provides Set, a context manager which sets one or more contextvars variables upon activation and resets them to their previous values at exit.

Usage:

import contextvars, with_contextvars
A = contextvars.ContextVar("A")
B = contextvars.ContextVar("B")
A.set("Hello,")
B.set("world!")
print(A.get(), B.get())
# prints: Hello, world!
with with_contextvars.Set((A, "other"), (B, "value")):
    print(A.get(), B.get())
    # prints: other value
print(A.get(), B.get())
# prints: Hello, world!

Even the entirety of variable assignments of a contextvars.Context object (as obtained from contextvars.copy_context()) can be activated by initializing Set with its items:

with with_contextvars.Set(*context.items()):
    ...

However, using contextvars.Context.run() is more efficient and should be preferred where possible.

More information can be found in the documentation of Set.

Metadata

Release files for with-contextvars 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for with-contextvars 0.1.2
File Size Uploaded Provenance Actions
with_contextvars-0.1.2.tar.gz 2.8 kB Without provenance Details for with_contextvars-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for with-contextvars 0.1.2
File Interpreter ABI Platform Actions
with_contextvars-0.1.2-py3-none-any.whl Python 3 none any Details for with_contextvars-0.1.2-py3-none-any.whl

Total release size: 6.4 kB

Release files / with_contextvars-0.1.2.tar.gz

Download URL with_contextvars-0.1.2.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb26d9a51f310cef9fb306cb04b09e87a3c0378059327bd2b5a6ea66c5ab7ce7
BLAKE2b-256 checksum
How to use checksums
061d1225d1c36e074c31fa75267aa70042a086c0c21f35a20a42e8eef628ed32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.9.2 Linux/5.10.0-26-amd64

Release files / with_contextvars-0.1.2-py3-none-any.whl

Download URL with_contextvars-0.1.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aae290cd363aa35560e4f1c3959a98b025457b8319c8d63f624b7825e51996e
BLAKE2b-256 checksum
How to use checksums
fdc80269fdca6fab81ec9aa487df5bc3f09fb4577fb3d49a6f6682a5cb466579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.9.2 Linux/5.10.0-26-amd64

Security for with-contextvars 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page