Python Dotenv (DEPRECATED `dotenv` package)

0.9.9 · deprecated · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates the recommended way to load environment variables using the `python-dotenv` library. It explicitly advises against installing the deprecated `dotenv` package and provides a functional example for `python-dotenv`.

# 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')

view raw JSON →