Navigate:
python-dotenv
~$PYTH0.2%

python-dotenv: Load environment variables from .env files

Parse and load .env files into Python environments.

LIVE RANKINGS • 10:58 AM • STEADY
OVERALL
#276
99
DEVELOPER TOOLS
#52
33
30 DAY RANKING TREND
ovr#276
·Devel#52
STARS
8.6K
FORKS
500
7D STARS
+16
7D FORKS
+5
See Repo:
Share:

Learn more about python-dotenv

python-dotenv is a Python library for parsing and loading environment configuration from .env files into the process environment. It reads files using Bash-like syntax, supporting features such as variable expansion, multiline values, and quoted strings. The library provides both programmatic APIs (load_dotenv and dotenv_values functions) and a command-line interface for managing .env files. It is commonly used in development workflows to avoid hardcoding configuration values while maintaining compatibility with production systems that source configuration from actual environment variables.

python-dotenv

1

Non-destructive loading

By default, load_dotenv does not override existing environment variables unless explicitly configured, allowing environment variables set outside the .env file to take precedence.

2

Multiple loading modes

Supports loading from filesystem paths, searching up the directory tree, or parsing from arbitrary streams such as StringIO objects, enabling configuration from various sources beyond .env files.

3

Bash-like syntax support

Implements Bash-compatible .env file parsing including variable expansion with ${VAR} syntax, multiline values, and quoted string handling, reducing the need to learn a separate configuration format.


from dotenv import load_dotenv
import os

# Load variables from .env file into environment
load_dotenv()

# Access environment variables
api_key = os.getenv('API_KEY')
database_url = os.getenv('DATABASE_URL')

print(f"Connected to: {database_url}")

vv1.2.1

v1.2.1

  • Support reading.env from FIFOs (Unix) by @sidharth-sudhir in
  • Update CI to use trusted publishing on PyPI
  • @sidharth-sudhir made their first contribution in
vv1.2.0

v1.2.0

  • style: upgrade to use ruff by @theskumar in
  • Use sys.exit() instead of exit() by @theskumar in
  • feat: add `PYTHONDOTENVDISABLED` flag to disable load_dotenv (fixes #510) by @matthewfranglen in
  • Added Python@3.14: Github CI & tox.ini by @23f3001135 in
  • ocs: clarify what load_dotenv() does in README by @cybercoded in
vv1.1.1

v1.1.1: fix: ensure find_dotenv work reliably on python 3.13 by @theskumar in

  • fix: ensure find_dotenv work reliably on python 3.13 by @theskumar in
  • fix(cli): issue with execvpe on Windows by @wrongontheinternet in
  • @wrongontheinternet made their first contribution in


[ EXPLORE MORE ]

Related Repositories

Discover similar tools and frameworks used by developers