The `load-dotenv` library, currently at version 0.1.0, provides a lightweight wrapper that automatically and implicitly loads environment variables from `.env` files. It essentially re-exports the core functionality of the popular `python-dotenv` library, offering a simple interface to manage environment variables for development. It has a low release cadence given its wrapper nature.
pip install load-dotenvVerified import paths — ran on the pinned version, not inferred.
Initializes environment variables by calling `load_dotenv()`. This will search for a `.env` file in the current directory and its parents, loading any key-value pairs found into `os.environ`. Access variables using `os.getenv()`.
To force `load-dotenv` to overwrite existing shell variables, pass `override=True` to the function: `load_dotenv(override=True)`.
`load_dotenv()` searches for the `.env` file upwards from the current working directory. Ensure your `.env` file is in the project root or a parent directory, or explicitly provide the path: `load_dotenv(dotenv_path='/path/to/your/.env')`.
`.env` files often contain sensitive information (API keys, database credentials). Always add `.env` to your `.gitignore` file. Use environment variables directly in production environments and consider dedicated secrets management systems.
`KEY="value"` will include the quotes in the loaded string. For standard string values, generally omit quotes (`KEY=value`). `KEY=` will result in an empty string (`''`), not `None`. Handle empty strings explicitly when accessing variables.
Ensure `load_dotenv()` is called early in your application's entry point. Verify `MY_VAR` exists in your `.env` file and that the file is correctly placed (or specify `dotenv_path`). Use `os.getenv('MY_VAR', 'default_value')` to provide fallbacks and prevent `TypeError`.If you intend to prioritize values from `.env` over existing shell variables, call `load_dotenv(override=True)`.
Place your `.env` file in the project's root directory. Alternatively, provide the explicit path to your `.env` file using the `dotenv_path` argument: `load_dotenv(dotenv_path='/path/to/your/.env')`.
No resource links recorded.