# pydoc > dotenv

---
type: CommandReference
command: dotenv
mode: pydoc
section: ""
source: pydoc3
---

## Quick Reference
- `load_dotenv()` — Load .env file and set environment variables
- `dotenv_values()` — Parse .env file and return dict
- `find_dotenv()` — Locate .env file in parent directories
- `set_key(dotenv_path, key, value)` — Set a key in .env file
- `unset_key(dotenv_path, key)` — Remove a key from .env file
- `get_key(dotenv_path, key)` — Get value of a key
- `get_cli_string()` — Generate shell command string from arguments
- `load_ipython_extension()` — Load as IPython extension

## Name
dotenv — Read key-value pairs from a .env file and load them into environment variables.

## Synopsis
Import `dotenv` to access functions for managing .env files:

python
import dotenv
from dotenv import load_dotenv, dotenv_values, find_dotenv, set_key, unset_key, get_key, get_cli_string, load_ipython_extension
Key functions are described below.

## Functions
- `dotenv_values(dotenv_path=None, stream=None, verbose=False, encoding=None)` — Parse a .env file and return a dict. Keys without values are stored as `None`. If both `dotenv_path` and `stream` are `None`, `find_dotenv()` is used.
- `load_dotenv(dotenv_path=None, stream=None, verbose=False, override=False, encoding=None)` — Load variables from a .env file into the environment. Returns `True` if at least one variable is set. Disabled if `PYTHON_DOTENV_DISABLED` is truthy. If paths are `None`, uses `find_dotenv()`.
- `find_dotenv(filename='.env', ...)` — Search upward in directories for the given file. Returns the file path if found, or an empty string.
- `set_key(dotenv_path, key, value, quote_mode='always', export=False, encoding=None, follow_symlinks=False)` — Add or update a key/value in the .env file. Creates the file if missing. Does not follow symlinks by default.
- `unset_key(dotenv_path, key, quote_mode='always', encoding=None, follow_symlinks=False)` — Remove a key from the .env file. Raises an error if the file does not exist or the key is missing. Does not follow symlinks by default.
- `get_key(dotenv_path, key, encoding=None)` — Get the value of a key from .env. Returns `None` if the key is not found or has no value.
- `get_cli_string(arguments)` — Returns a string suitable for running as a shell script, useful for translating arguments to a `local` or `run` command in fabric.
- `load_ipython_extension(ipython)` — Register IPython magic functions for dotenv.

## Examples

python
from dotenv import load_dotenv, dotenv_values

# Load .env into environment
load_dotenv()

# Access a variable
import os
print(os.getenv("SECRET_KEY"))

# Get .env content as dict
config = dotenv_values(".env")
print(config.get("DATABASE_URL"))

# Modify .env file
from dotenv import set_key, unset_key
set_key(".env", "NEW_KEY", "value")
unset_key(".env", "OLD_KEY")
## See Also
- [python-dotenv on PyPI](https://pypi.org/project/python-dotenv/)