Skip to main content

A utility tool to create .env files

Project description

A utility tool to create .env files Build Status Coverage Python Version Docs wemake-python-styleguide

dump-env takes an .env.template file and some optional environmental variables to create a new .env file from these two sources. No external dependencies are used.


Why do we need such a tool? Well, this tool is very helpful when your CI is building docker (or other) images. Previously we had some complex logic of encrypting and decrypting files, importing secret keys and so on. Now we can just create secret variables for our CI, add some prefix to it, and use dump-env to make our life easier.


$ pip install dump-env


This quick demo will demonstrate the main and the only purpose of dump-env:

$ dump-env --template=.env.template --prefix='SECRET_ENV_' > .env

This command will:

  1. take .env.template
  2. parse its keys and values
  3. read and all the variables from the environment starting with SECRET_ENV_
  4. remove this prefix
  5. mix it all together, environment vars may override ones from the template
  6. sort keys in alphabetic order
  7. dump all the keys and values into the .env file

Advanced Usage

Multiple prefixes

$ dump-env -t .env.template -p 'SECRET_ENV_' -p 'ANOTHER_SECRET_ENV_' > .env

This command will do pretty much the same thing as with one prefix. But, it will replace multiple prefixes. Further prefixes always replace previous ones if they are the same. For example:

$ export SECRET_TOKEN='very secret string'
$ export SECRET_ANSWER='13'
$ dump-env -p SECRET_ -p ANOTHER_SECRET_ENV_
TOKEN=very secret string

Strict env variables

In case you want to be sure that YOUR_VAR exists in your enviroment when dumping, you can use --strict flag:

$ dump-env --strict YOUR_VAR -p YOUR_
Missing env vars: YOUR_VAR

Oups! We forgot to create it! Now this will work:

$ export YOUR_VAR='abc'
$ dump-env --strict YOUR_VAR -p YOUR_

Any number of --strict flags can be provided. No more forgotten template overrides or missing env vars!

Creating secret variables in some CIs

Real-world usages

Projects that use this tool in production:


You might also be interested in:



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dump-env, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size dump_env-1.1.1-py3-none-any.whl (10.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dump-env-1.1.1.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page