{"id":14550,"library":"environ","title":"Environ Global State Management","description":"`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.","status":"abandoned","version":"1.0","language":"en","source_language":"en","source_url":"https://github.com/peterbe/environ","tags":["global state","application state","context manager","abandoned"],"install":[{"cmd":"pip install environ","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"environ","correct":"from environ import environ"}],"quickstart":{"code":"from environ import environ\n\nenviron.set('app_config_key', 'initial_value')\nassert environ.get('app_config_key') == 'initial_value'\n\n# Temporarily override values within a context\nwith environ(temporary_key='context_value'):\n    assert environ.get('app_config_key') == 'initial_value'\n    assert environ.get('temporary_key') == 'context_value'\n    environ.set('another_context_key', 'inside_context')\n    assert environ.get('another_context_key') == 'inside_context'\n\n# Outside the context, temporary values are reverted\nassert environ.get('app_config_key') == 'initial_value'\nassert environ.get('temporary_key') is None\nassert environ.get('another_context_key') is None","lang":"python","description":"This example demonstrates how to set and retrieve global application state using `environ`, and how to use its context manager for temporary overrides."},"warnings":[{"fix":"Do not use for new projects. For existing projects, migrate to `os.environ` for environment variables, or a dependency injection system for application state.","message":"This library is **abandoned** and has not been updated since its 1.0 release in 2012. It is not officially supported on modern Python versions (e.g., Python 3.8+). While it might still function for simple cases, compatibility issues or unexpected behavior are likely to arise. Consider alternative solutions for global state management or environment variables.","severity":"breaking","affected_versions":"1.0"},{"fix":"Use `os.environ` for OS environment variables. Use `environ.set()` and `environ.get()` for `environ` library's intended application state.","message":"The library's name `environ` is highly misleading. It is **not** designed for managing operating system environment variables (like `PATH` or `HOME`). Instead, it manages application-specific global state. For OS environment variables, use Python's built-in `os.environ`.","severity":"gotcha","affected_versions":"1.0"},{"fix":"Be extremely cautious when using global state. For testing, ensure proper setup and teardown to reset state. Consider dependency injection or passing state explicitly for better control.","message":"`environ` uses a global singleton object, which can make testing and managing application state challenging. Modifying global state can lead to side effects, make tests difficult to isolate, and introduce hard-to-debug issues in complex applications.","severity":"gotcha","affected_versions":"1.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install environ` to install the package.","cause":"The 'environ' package has not been installed.","error":"ModuleNotFoundError: No module named 'environ'"},{"fix":"Access methods directly on the `environ` object, e.g., `environ.set('key', value)` or `environ.get('key')`.","cause":"The `environ` object is a singleton instance for managing state, not a constructor to be called like `environ()`.","error":"TypeError: 'Environ' object is not callable"},{"fix":"Use the dedicated `set` and `get` methods: `environ.set('key', value)` and `value = environ.get('key')`.","cause":"The `environ` object is not a dictionary and does not support direct item assignment or access (e.g., `environ['key'] = value` or `value = environ['key']`).","error":"TypeError: 'Environ' object does not support item assignment"}],"ecosystem":"pypi"}