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,843stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity72
Maintenance52
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
87/100Excellent
Architecture80
Code Quality85
Innovation88
Learning Curve95

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 69 apps in this directory

Python
66%
Apache 2.0

Agent Control

AI Agents

295

An open-source runtime control plane for AI agents — define safety guardrails once, apply them across agents built on LangChain, CrewAI, Google ADK, or AWS Strands, and update controls without redeploying code.

View details
79
Repo Health
71
Technical
70
Dependency
Built with
Python66%
TypeScript33%
Updated yesterday
TypeScript
59%
Other

agenta

Developer Tools · Devops · AI Development

4,489

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript59%
Python39%
Updated today
Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
Python
88%
Apache 2.0

ART

AI Development

10,603

Give your LLM agents on-the-job training—ART lets you apply GRPO reinforcement learning to any multi-step agentic workflow with minimal code changes.

View details
85
Repo Health
82
Technical
72
Dependency
Built with
Python88%
Cuda10%
Updated today
Python
97%
MIT

auto-news

AI Assistants · Productivity

906

An AI-powered personal news aggregator that filters multi-source feeds through LLMs and delivers curated, noise-free summaries to your Notion workspace.

View details
43
Repo Health
53
Technical
66
Dependency
Built with
Python97%
Updated 1 years ago
Python
62%
MIT

AutoGen

AI Development · Automation

60,518

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
57
Repo Health
78
Technical
75
Dependency
Built with
Python62%
C#25%
TypeScript12%
Updated 4 months ago
Python
68%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,687

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python68%
TypeScript31%
Updated today
TypeScript
48%
AGPL 3.0

Banana Slides

AI Design Tools · Productivity

15,476

AI-native PPT generator with Vibe editing, multi-LLM support, and fully editable PPTX export

View details
83
Repo Health
82
Technical
71
Dependency
Built with
TypeScript48%
Python47%
Updated 3 days 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

Search