A Python library that loads environment variables from .env files, enabling 12-factor application configuration management.
python-dotenv is a Python library that loads environment variables from `.env` files into the application's environment. It solves the problem of managing configuration separately from code, especially during development, by allowing developers to store settings in a file that mimics production environment variables. This ensures applications follow the 12-factor app methodology, making them more portable and easier to configure across different environments.
Python developers building 12-factor applications, web developers using frameworks like Django or Flask, and anyone needing to manage environment-specific configuration without hardcoding values.
Developers choose python-dotenv for its simplicity, seamless integration with existing environment variable usage, and adherence to 12-factor principles. It provides a lightweight, zero-dependency solution with advanced features like variable expansion, stream parsing, and a CLI, making configuration management both flexible and robust.
Reads key-value pairs from a .env file and can set them as environment variables. It helps in developing applications following the 12-factor principles.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
With a single call to `load_dotenv()`, environment variables are automatically loaded from .env files, eliminating manual setup for development.
Supports Bash-like syntax with variable expansion, multiline strings, and comments, as detailed in the File Format section, making .env files versatile.
The `dotenv_values()` function reads .env files into a dictionary without modifying the environment, enabling advanced config management without side effects.
Can parse configuration from any stream (e.g., network) and includes IPython magic commands, offering use cases beyond local file loading.
Only handles string key-value pairs without type checking or schema validation, requiring manual conversion for data types like integers or booleans.
The precedence rules for variable expansion with `override=True` or `False` can be confusing, potentially leading to bugs if misunderstood, as noted in the File Format section.
While it adheres to 12-factor principles, it lacks framework-specific features found in alternatives like django-environ, which might be necessary for complex Django projects.