python-dotenv

Load environment variables from a .env file into Python's os.environ, the standard way to keep 12-factor config out of your code

Library
PyPI
v1.2.3
8,883 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
63 /100 Good
Development Activity 48
Maintenance 40
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 80
Code Quality 85
Innovation 88
Learning Curve 95

python-dotenv reads key-value pairs from a .env file and sets them as environment variables, letting Python applications follow 12-factor-app configuration practices without hand-rolling a parser. A single load_dotenv() call at process startup is enough to make .env values available through os.environ exactly as if they had been exported in the shell, while dotenv_values() offers a non-mutating variant that returns a plain dict for more deliberate configuration layering.

Beyond the two core functions, the library ships variable expansion (${VAR} interpolation with fallback to the real environment), multiline and quoted values, a dotenv CLI for inspecting and editing .env files from the shell, and an IPython/Jupyter magic extension. It has no runtime dependencies for its core API, is fully typed (PEP 561 py.typed), and has been the de facto standard for environment-based configuration in the Python ecosystem for over a decade.

What You Get

  • load_dotenv() to parse a .env file and merge its values into os.environ, with override controlling precedence against variables already set
  • dotenv_values() for a non-mutating read that returns a dict, enabling layered configs (e.g. {**dotenv_values('.env.shared'), **dotenv_values('.env.secret'), **os.environ})
  • POSIX-style variable expansion (${DOMAIN}) so values can reference each other or fall back to real environment variables
  • A dotenv command-line tool (pip install "python-dotenv[cli]") to get/set/list/run against a .env file without opening an editor
  • An IPython/Jupyter %dotenv magic for loading environment files inside notebooks
  • Support for multiline, quoted, and FIFO-stream values, with clear parse-error warnings for malformed lines

Common Use Cases

  • Loading local development secrets (API keys, database URLs) from a git-ignored .env file at app startup
  • Layering shared and secret configuration files before falling back to real environment variables in staging/production
  • Feeding environment variables into Django, Flask, FastAPI, or any framework that reads config via os.environ
  • Driving reproducible local scripts and IPython notebooks without leaking credentials into shell history
  • Wrapping subprocess invocations with dotenv run -- <command> so tools that expect a real environment work unmodified

Under The Hood

Architecture - The codebase separates parsing from application: parser.py tokenizes a .env stream into Binding records (key, value, original source line, error flag) using a small set of compiled regexes for quoted/unquoted keys and values, variables.py resolves ${VAR} interpolation against already-parsed bindings and os.environ, and main.py’s DotEnv class orchestrates file/stream reading, invalid-line warnings, and the public load_dotenv/dotenv_values/get_key/set_key/unset_key/find_dotenv functions. cli.py and ipython.py are thin wrappers around that same core, so the CLI and Jupyter magic share identical parsing behavior with the library API.

Tech Stack - Pure Python with no third-party runtime dependencies for the core API; the only optional dependency is click, pulled in solely via the [cli] extra for the dotenv command-line tool. The package is fully typed (py.typed marker for PEP 561), builds with setuptools, targets Python 3.10+, and is linted with ruff and type-checked with mypy per the repo’s ruff.toml/pyproject.toml configuration.

Code Quality - The tests/ directory contains roughly 77 test functions across ten files covering the parser, variable expansion, CLI, IPython integration, FIFO streams, and zip-import edge cases, with pyproject.toml configuring coverage reporting via tool.coverage. Naming is consistent and narrow (single-purpose modules for parsing, variables, and CLI), and the public functions are fully type-annotated, giving strong static-analysis coverage for a project of this size.

API Design - The library optimizes hard for a one-line getting-started path: from dotenv import load_dotenv; load_dotenv() is the entire integration for the common case, with dotenv_values() offered as a symmetric non-mutating alternative for teams that want to layer configuration explicitly rather than mutate os.environ implicitly. Function names (load_dotenv, get_key, set_key, unset_key, find_dotenv) read as a coherent CRUD-like vocabulary, and the README leads with copy-pasteable examples for every use case rather than requiring readers to infer usage from a reference doc.

Used by 73 apps in this directory

Rust
63%
MIT

PostgresML

AI Development · Databases

6,825

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

39,975

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 1 weeks ago
TypeScript
97%
MIT

Promptfoo

AI Development

25,506

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
JavaScript
50%
AGPL 3.0

QRev

AI Agents · CRM

363

Open source AI-first sales platform that replaces Salesforce with autonomous agents handling prospecting, outreach, and lead management at scale.

View details
38
Repo Health
68
Technical
63
Dependency
Built with
JavaScript 50%
Python 28%
TypeScript 14%
Updated 8 months ago
Python
46%
Other

Redash

Analytics · Data Engineering

28,817

Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.

View details
92
Repo Health
74
Technical
60
Dependency
Built with
Python 46%
JavaScript 30%
TypeScript 17%
Updated 1 weeks ago
TypeScript
65%
MIT

Scalar

Developer Tools

16,198

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 1 weeks ago
Python
76%
Apache 2.0

Second Me

AI Assistants · Productivity

15,690

Train a locally hosted AI twin on your own memories—then connect it to the world through a decentralized identity network.

View details
41
Repo Health
75
Technical
67
Dependency
Built with
Python 76%
TypeScript 19%
Updated 1 years ago
Python
64%
AGPL 3.0

Shadowbroker

Analytics · Monitoring · Security

11,261

Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.

View details
84
Repo Health
83
Technical
71
Dependency
Built with
Python 64%
TypeScript 32%
Updated 1 weeks ago
Python
78%
AGPL 3.0

Skyvern

AI Agents · Automation

23,088

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 78%
TypeScript 20%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers