Repolode
theskumar

theskumar/python-dotenv

A Python library that loads key-value pairs from a .env file into environment variables, following 12-factor app practices.

Stars
8,916
Forks
619
Open issues
126
Last commit
10 days ago

What is it?

python-dotenv reads key-value pairs from a .env file and sets them as environment variables. It is aimed at 12-factor applications, which take their configuration from the environment, so developers can keep those settings in a local file during development without exporting them in the shell each time.

The main entry point is load_dotenv(), which by default searches for a .env file, adds its values to os.environ, and leaves existing variables unchanged unless override=True is passed. dotenv_values() returns the parsed values as a dict without touching the environment, and both functions can read from a stream instead of a file. A dotenv command-line tool can set, list, and run commands with variables loaded from the file.

The file format resembles Bash, supporting quoting, comments, the export prefix, multiline values, and ${VAR} expansion. The package is installable with pip and includes an IPython extension.

Key features

  • 01Loads .env file values into os.environ, without overriding existing variables by default.
  • 02Returns parsed values as a dict via dotenv_values() without modifying the environment.
  • 03Reads configuration from streams as well as files.
  • 04Supports Bash-like syntax with quoting, comments, export prefixes and multiline values.
  • 05Expands variables written as ${VAR} inside values.
  • 06Includes a dotenv CLI for setting, listing and running commands with loaded variables.
  • 07Provides an IPython extension for loading .env files.

Use cases

  • Keeping database URLs and API keys for a Python web app in a local .env file during development.
  • Loading configuration from a non-filesystem source, such as a network stream, into a Python program.
  • Running a script with variables from a .env file via the dotenv run command.
  • Reading .env values into a dict for configuration merging without changing os.environ.

Quick start

  1. 1

    Install the library from PyPI

    pip install python-dotenv
  2. 2

    Create a .env file in your project root with your settings

  3. 3

    Call load_dotenv() at the start of your application

Things to know

  • The .env file format is not formally specified and may change over time.

Topics

FAQ

What is python-dotenv?
A Python library that loads key-value pairs from a .env file into environment variables, following 12-factor app practices. python-dotenv reads key-value pairs from a .env file and sets them as environment variables. It is aimed at 12-factor applications, which take their configuration from the environment, so developers can keep those settings in a local file during development without exporting them in the shell each time.
Is python-dotenv free to use? What license does it have?
python-dotenv is open source under the BSD-3-Clause license. Check the license terms before using it in commercial products.
Is python-dotenv still maintained?
Actively maintained. The last commit to python-dotenv was on Oct 28, 2026.
What can I use python-dotenv for?
Keeping database URLs and API keys for a Python web app in a local .env file during development. Loading configuration from a non-filesystem source, such as a network stream, into a Python program. Running a script with variables from a .env file via the dotenv run command. Reading .env values into a dict for configuration merging without changing os.environ.
How do I install python-dotenv?
Install the library from PyPI: pip install python-dotenv Create a .env file in your project root with your settings Call load_dotenv() at the start of your application
Where can I get python-dotenv?
The source code and installation instructions are on GitHub: https://github.com/theskumar/python-dotenv

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects