This package is not maintained anymore. Please switch to 'contextvars-registry'.
Project description
Project Moved
The project was renamed to `contextvars-registry` and moved to:
This package is not maintained anymore. Please switch to `contextvars-registry`.
Description
contextvars-extras is a set of extensions for the Python’s contextvars module.
In case you are not familiar with the contextvars module, its ContextVar objects work like Thread-Local storage, but better: they are both thread-safe and async task-safe, and they can be copied (all existing vars copied in O(1) time), and then you can run a function in the copied and isolated context.
The contextvars is a powerful module, but its API seems too low-level.
So this contextvars_extras package provides some higher-level additions on top of the standard API, like, for example, organizing ContextVar objects into registry classes, with nice @property-like access:
from contextvars_extras import ContextVarsRegistry
class CurrentVars(ContextVarsRegistry):
locale: str = 'en'
timezone: str = 'UTC'
current = CurrentVars()
# calls ContextVar.get() under the hood
current.timezone # => 'UTC'
# calls ContextVar.set() under the hood
current.timezone = 'GMT'
# ContextVar() objects can be reached as class members
CurrentVars.timezone.get() # => 'GMT'
That makes your code more readable (no more noisy .get() calls), and it is naturally firendly to typing, so static code analysis features (like type checkers and auto-completion in your IDE) work nicely.
Check out the full documentation
Links
Read the Docs: https://contextvars-extras.readthedocs.io
GitHub repository: https://github.com/vdmit11/contextvars-extras
Python package: https://pypi.org/project/contextvars-extras/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file contextvars_extras-0.7.0.tar.gz
.
File metadata
- Download URL: contextvars_extras-0.7.0.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.4.0-172-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4823d1f3b0e8ef863d5a622b9effbdd3a34b6bb11a6d6ab0fbcb6579d59aad6 |
|
MD5 | 5091123cf2abdf77f98ee9ca6542ade8 |
|
BLAKE2b-256 | 8c1b82ce324fd283a1083e5a9b1eaba07cb1748486caf953bc26d142d0da39c2 |
File details
Details for the file contextvars_extras-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: contextvars_extras-0.7.0-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.4.0-172-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e82956b206d5fd28650d37fb869cee743aad62f3cf54ed607a85107713da944 |
|
MD5 | 9181a8832b404b17d682079f09de6809 |
|
BLAKE2b-256 | 200ad3116413f9ca488cb72c5cee8e6077ddb8014fb2b6aabd2d634cd355923e |