Registry / devops / load-dotenv

load-dotenv

JSON →
library0.1.0pypiunverified

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-dotenv
INSTALL
IMPORT
SIG · LOAD-DOTENV
L
load-dotenv
devopsenv0.1.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load_dotenv
from load_dotenv import load_dotenv
from dotenv import load_dotenv
While `load-dotenv` re-exports `python-dotenv`'s function, direct import from 'dotenv' bypasses this wrapper.

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()`.

import os from load_dotenv import load_dotenv # Create a dummy .env file for demonstration # In a real scenario, this file would exist beforehand with open('.env', 'w') as f: f.write('DB_HOST=localhost\n') f.write('DB_USER=admin\n') f.write('DB_PASSWORD=secret_password\n') load_dotenv() # take environment variables from .env. # Access environment variables db_host = os.getenv("DB_HOST") db_user = os.getenv("DB_USER") db_password = os.getenv("DB_PASSWORD") print(f"DB Host: {db_host}") print(f"DB User: {db_user}") print(f"DB Password: {db_password}") # Clean up the dummy .env file os.remove('.env')
Debug
Known issues
gotcha`load_dotenv()` does not overwrite existing environment variables by default.
fix
To force `load-dotenv` to overwrite existing shell variables, pass `override=True` to the function: `load_dotenv(override=True)`.
affects: All versions (inherent behavior of underlying `python-dotenv`).
gotchaThe `.env` file location search behavior can be unexpected.
fix
`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')`.
affects: All versions (inherent behavior of underlying `python-dotenv`).
gotchaCommitting `.env` files to version control poses a significant security risk.
fix
`.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.
affects: All versions.
gotchaValues with quotes or empty values are parsed literally, potentially leading to unexpected results.
fix
`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.
affects: All versions (inherent behavior of underlying `python-dotenv`).
Errors
Common errors & fixes
KeyError: 'MY_VAR' or TypeError: 'NoneType' object is not subscriptable
The environment variable `MY_VAR` was not loaded, not present in the `.env` file, or the `.env` file itself was not found/loaded when accessing `os.environ['MY_VAR']` or calling a method on `os.getenv('MY_VAR')` when it returns `None`.
fix
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`.
Environment variable not updating / Old value of variable is loaded
`load_dotenv()` by default does not overwrite existing environment variables that were already set in the shell before the script runs.
fix
If you intend to prioritize values from `.env` over existing shell variables, call `load_dotenv(override=True)`.
'.env file not found' (when expecting variables to load)
The `load_dotenv()` function couldn't locate a `.env` file in the current directory or any parent directories as it searches upwards.
fix
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')`.
Upgrade
Version history
0.1.0latest on PyPI · released Sep 2, 2022
Audit
Dependencies
python-dotenvrequiredCore functionality is provided by python-dotenv; load-dotenv is a wrapper re-exporting its functions.
Agent activity
3 hits · last 30 days
node
2
Resources

No resource links recorded.

load-dotenv — pip install load-dotenv · libregistry