python-decouple provides a clean, strict separation of configuration settings from code, inspired by The Twelve-Factor App methodology. It allows you to store parameters in environment variables, `.env` files, or `settings.ini` files, making it easy to manage different environments (development, staging, production). The current version is 3.8, and it sees active maintenance with minor releases typically a few times a year addressing bug fixes and minor improvements.
pip install python-decoupleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `decouple.config` to load settings from a `.env` file (or environment variables). It shows retrieving a simple string, casting a boolean, providing a default value, and parsing a comma-separated string into a list using a custom cast function. `decouple` automatically looks for `.env` or `settings.ini` files in the current directory or parent directories.
Always provide a `default` parameter to `config()` (e.g., `config('MY_KEY', default=None)`) or ensure the key exists in your `settings.ini` file if you were relying on implicit `None` returns for missing INI keys.Always explicitly provide a `default` value if a setting is optional (e.g., `config('OPTIONAL_KEY', default=None)`). Otherwise, ensure all required settings are defined in your environment or configuration files.Upgrade to `v3.7` or later. If upgrading is not immediately possible, avoid using `Csv` or similar string-splitting casts with `default=None` in older versions. Instead, provide an empty list as a default: `config('MY_LIST', cast=Csv(), default=[])`.Be mindful of where you define your settings. For local development, `.env` is often preferred. For production, environment variables are typically used. Ensure you're not inadvertently overriding critical settings with lower-precedence definitions.
No dependency data recorded yet.