1. License
“Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met”
Any use is allowed; keep the copyright notice and license text when you ship its files.
github.com/theskumar/python-dotenv/blob/main/LICENSE3. Used by agents' projects
Dependency in 568 public GitHub projects set up for AI coding agents that we scanned (9.1%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error
What python-dotenv does
python-dotenv is a free Python library that reads a small text file named .env and hands its lines to your program as settings. You keep keys, passwords and addresses in that file on your own computer, out of the code. On the server the same program reads the real settings instead.
What people build with it
Keep service keys out of code
Your app calls a paid AI or payment service; the secret key sits in .env on your laptop, never in the code you share or push.
Same code on laptop and server
On your computer settings come from .env; on the hosting service the real settings win, with no code change.
Read settings without changing anything
A small script reads the values from .env into a plain list of names and values, for example to show which settings are missing.
Shared and private settings files
The team shares one file with ordinary settings, and each person keeps a second file with their own secrets.
Run any command with the settings
Start a script, a worker or a test run with the values from .env, without changing that program.
Notebook experiments with keys
In a Jupyter notebook, load your keys from .env with two lines instead of pasting them into a cell.
python-dotenv popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How python-dotenv is used
- python-dotenv is a dependency in 568 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (35.0% of the 1,623 Python ones), #3 of 299 in dev workflow and config.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 5,334; those are left out of every share on this page.
- The most used alternative in our scan is Pydantic Settings (219 projects).
- Projects that use it most often also use Pydantic (49.3%), Uvicorn (43.8%), Requests (42.6%).
- It is more common in projects set up for OpenClaw (12.0%) than for OpenAI Codex (4.3%).
By coding agent
Often used with
python-dotenv in practice
Strengths
<code>load_dotenv()</code> does not override variables that are already set, because it defaults to <code>override=False</code>. A <code>.env</code> file can sit in development while deployed values stay in charge. Pass <code>override=True</code> to reverse this.
<code>dotenv_values</code> parses the file and returns a <code>dict</code> without touching <code>os.environ</code>. The README shows it merging <code>.env.shared</code>, <code>.env.secret</code> and <code>os.environ</code> into one config.
Both <code>load_dotenv</code> and <code>dotenv_values</code> take a <code>stream</code> argument. The docs give the network as an example source. The file format section adds that reading from FIFOs (named pipes) on Unix is supported.
Setting <code>PYTHON_DOTENV_DISABLED=1</code> stops <code>load_dotenv()</code> from loading anything. The docs suggest this for production, or when a third-party package calls it.
Watch out for
The maintainers say the <code>.env</code> format is not formally specified and is still changing. Files should "mostly look like Bash files", but that is a guide, not a guarantee.
Variable references must use braces. A bare <code>$DOMAIN</code> is left as is.
With <code>override=False</code>, an expanded variable takes its value from the environment first and from the <code>.env</code> file second. With <code>override=True</code> or <code>dotenv_values()</code>, the file comes first. The same <code>.env</code> can therefore produce different values.
Layer shared, secret and real environment values
import os
from dotenv import dotenv_values
config = {
**dotenv_values(".env.shared"), # load shared development variables
**dotenv_values(".env.secret"), # load sensitive variables
**os.environ, # override loaded values with environment variables
}More about python-dotenv
Head to head
- python-dotenv vs Pydantic Settings used together in 125 projects
Packages around it
- requests: HTTP client
- pydantic: Data validation
- uvicorn: ASGI server
- fastapi: Web API framework
- solders: Solana Python bindings
- numpy: Numerical arrays
More in Dev workflow and config
Alternatives
python-dotenv This page
Pick Pydantic Settings when you also want each setting checked and turned into the right type (number, true/false) when the app starts.
Pick environs when you want .env loading plus typed helpers such as reading a number, a list or a URL from a setting.
Pick python-decouple when settings may come from either .env or an .ini file and you want defaults and casting in one call.
Get started
Tell your AI assistant
“Use python-dotenv (pin python-dotenv==1.2.4, Python 3.10+) to load settings from a .env file with an explicit path at startup, read keys with os.environ[...], add .env to .gitignore and commit a .env.example with empty values.”
Install the package. Its name is python-dotenv; in code you import dotenv.
pip install python-dotenvLoad the file at the start of your program, then read settings as usual.
from dotenv import load_dotenv load_dotenv() # reads variables from a .env file and sets them in os.environPut a .env file in the project's root folder and add .env to .gitignore.
# Development settings DOMAIN=example.org ADMIN_EMAIL=admin@${DOMAIN} ROOT_URL=${DOMAIN}/app
Rules for your agent
## python-dotenv
- Install with `pip install python-dotenv`; add the `[cli]` extra only if the `dotenv` command is needed.
- Call `load_dotenv()` once at startup, then read config through `os.environ` or `os.getenv`.
- Do not pass `override=True` unless `.env` values must beat variables already set in the environment; the default is `override=False`.
- Use `dotenv_values(".env")` when you need a dict and must not modify `os.environ`.
- Write variable references as `${VAR}`; bare `$VAR` is not expanded.
- Add `.env` to `.gitignore`, especially when it holds secrets like passwords.
- To stop `load_dotenv()` in production or inside third-party code, set `PYTHON_DOTENV_DISABLED=1` instead of editing calls.
Mistakes to avoid
Without a path it searches from the script's folder upward; in our run a script in tools/ skipped the .env in the current folder and picked up a different .env two levels higher.
The default keeps existing values; in our run PORT stayed 9000 until override=True.
Only the braced form is filled in; in our run BARE=$DOMAIN/shop came back unchanged.
Every value is text. In our run DEBUG=true arrived as the string 'true', so even 'false' counts as true.
The file holds secrets in plain text.
Questions
Does it replace settings that are already set on the server?
No, not by default. Pass override=True if the file should win.
Can one value use another, like ${DOMAIN}?
Yes, with braces. A bare $DOMAIN stays as written; our run showed the same.
Where does load_dotenv() look for the file?
Next to the Python script and then in the folders above it, not in the folder you started the program from.
Can a value span several lines?
Yes, if it is in single or double quotes.
Is it still maintained?
Yes. Version 1.2.4 came out on 2026-10-01 and more fixes are listed as unreleased.