Python Dotenv (DEPRECATED `dotenv` package)
This entry refers to the original `dotenv` package (pedroburon/dotenv, version 0.9.9), a deprecated and unmaintained library for loading environment variables from `.env` files. Most users intending to manage `.env` files in Python should instead use the actively maintained `python-dotenv` library. This package is no longer developed and lacks features, bug fixes, and security updates present in its modern alternatives. Its status is deprecated.
Warnings
- breaking The `dotenv` package (pedroburon/dotenv, version 0.9.9) is DEPRECATED and has not been maintained since 2017. It should not be used in new projects and existing projects should migrate.
- gotcha Most users intending to load environment variables from `.env` files are actually looking for the `python-dotenv` package, not `dotenv`. The `pip install dotenv` command installs the deprecated version.
- gotcha Despite sharing similar API calls like `load_dotenv()`, the deprecated `dotenv` package lacks critical features (e.g., handling variable expansion), bug fixes, and security updates present in `python-dotenv`.
- breaking Security vulnerabilities and unpatched bugs may exist in the unmaintained `dotenv` package, making its use risky, especially in production environments.
Install
-
pip install dotenv
Imports
- load_dotenv
from dotenv import load_dotenv
Quickstart
# It is strongly recommended to use 'python-dotenv' instead of 'dotenv'.
# First, uninstall the deprecated package if you have it:
# pip uninstall dotenv
# Then, install the recommended 'python-dotenv' package:
# pip install python-dotenv
# Example using 'python-dotenv':
from dotenv import load_dotenv
import os
# Create a dummy .env file for demonstration
with open('.env', 'w') as f:
f.write('MY_VAR="Hello from python-dotenv!"\n')
f.write('ANOTHER_VAR=123\n')
# Load environment variables from .env
load_dotenv()
# Access the variables
my_var = os.getenv('MY_VAR')
another_var = os.getenv('ANOTHER_VAR')
print(f"MY_VAR: {my_var}")
print(f"ANOTHER_VAR: {another_var}")
# Clean up the dummy .env file
os.remove('.env')