dump-env
raw JSON → 1.7.0 verified Fri May 01 auth: no python
A utility tool to create .env files from environment variables or dictionaries. Current version 1.7.0, supports Python 3.10+. Release cadence is irregular with major features added roughly yearly.
pip install dump-env Common errors
error TypeError: dump_env() missing 1 required positional argument: 'keys' ↓
cause Calling dump_env() without providing the 'keys' argument (a list of environment variable names).
fix
Pass a list of keys: dump_env(['MY_VAR'], filename='.env').
error ImportError: cannot import name 'dump_env' from 'dump_env' ↓
cause Tried to import using 'import dump_env' and then calling 'dump_env.dump_env()', but the module name clashes with the function name, leading to confusion.
fix
Use 'from dump_env import dump_env' and then call 'dump_env(...)'.
Warnings
breaking In version 1.0.0, Python 2 support was dropped. If you are still on Python 2, you cannot upgrade beyond 0.2.1. ↓
fix Upgrade to Python 3.6+ (or Python 3.10+ for v1.7.0) and use dump-env >=1.0.0.
deprecated Python 3.9 support was dropped in version 1.6.0. If your project requires Python 3.9, pin to dump-env <1.6.0. ↓
fix Pin dependency: 'dump-env<1.6.0' or upgrade to Python 3.10+.
gotcha dump_env() writes to stdout by default; if you forget to pass 'filename', output goes to console, not to a file. ↓
fix Always pass the 'filename' argument when you intend to write a .env file. Example: dump_env(['KEY'], filename='.env').
Imports
- dump_env wrong
import dump_envcorrectfrom dump_env import dump_env
Quickstart
from dump_env import dump_env
import os
os.environ['MY_VAR'] = 'hello'
dump_env(['MY_VAR'], filename='.env')
with open('.env') as f:
print(f.read())