python-dotenv

1.2.2 · active · verified Sat Mar 28

python-dotenv is a Python library that reads key-value pairs from a .env file and sets them as environment variables. The current version is 1.2.2, released in March 2026. The library is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to load environment variables from a .env file and access them using os.environ.

from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Access environment variables
SECRET_KEY = os.environ.get('SECRET_KEY', '')
DATABASE_PASSWORD = os.environ.get('DATABASE_PASSWORD', '')

print(f'SECRET_KEY: {SECRET_KEY}')
print(f'DATABASE_PASSWORD: {DATABASE_PASSWORD}')

view raw JSON →