Environ Global State Management

1.0 · abandoned · verified Fri Apr 17

`environ` is a small Python library providing a stack-based mechanism for managing global application state. It allows setting and retrieving values globally, with the ability to temporarily override values within a context manager. The library's latest version is 1.0, released in 2012, and it is no longer actively maintained or supported.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set and retrieve global application state using `environ`, and how to use its context manager for temporary overrides.

from environ import environ

environ.set('app_config_key', 'initial_value')
assert environ.get('app_config_key') == 'initial_value'

# Temporarily override values within a context
with environ(temporary_key='context_value'):
    assert environ.get('app_config_key') == 'initial_value'
    assert environ.get('temporary_key') == 'context_value'
    environ.set('another_context_key', 'inside_context')
    assert environ.get('another_context_key') == 'inside_context'

# Outside the context, temporary values are reverted
assert environ.get('app_config_key') == 'initial_value'
assert environ.get('temporary_key') is None
assert environ.get('another_context_key') is None

view raw JSON →