Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contextvars-extras

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contextvars-extras

This package is not maintained anymore. Please switch to 'contextvars-registry'.

  • 0.7.0
  • PyPI
  • Socket score

Maintainers
1

contextvars-extras

Project Moved

The project was renamed to contextvars-registry and moved to:

  • https://pypi.org/project/contextvars-registry/
  • https://github.com/vdmit11/contextvars-registry

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.

.. _contextvars: https://docs.python.org/3/library/contextvars.html .. _ContextVar: https://docs.python.org/3/library/contextvars.html#contextvars.ContextVar

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:

.. code:: python

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.

.. _typing: https://docs.python.org/3/library/typing.html

Check out the full documentation <https://contextvars-extras.readthedocs.io>_

.. |pypi badge| image:: https://img.shields.io/pypi/v/contextvars-extras.svg :target: https://pypi.org/project/contextvars-extras/ :alt: Python package version

.. |build badge| image:: https://github.com/vdmit11/contextvars-extras/actions/workflows/build.yml/badge.svg :target: https://github.com/vdmit11/contextvars-extras/actions/workflows/build.yml :alt: Tests Status

.. |docs badge| image:: https://readthedocs.org/projects/contextvars-extras/badge/?version=latest :target: https://contextvars-extras.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc