A utility tool to create .env files
Project description
A utility tool to create .env
files
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?
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.
Installation
$ pip install dump-env
Quickstart
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:
- take
.env.template
- parse its keys and values
- read and all the variables from the environment starting with
SECRET_ENV_
- remove this prefix
- mix it all together, environment vars may override ones from the template
- sort keys in alphabetic order
- 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'
$ export ANOTHER_SECRET_ENV_ANSWER='42'
$ export ANOTHER_SECRET_ENV_VALUE='0'
$ dump-env -p SECRET_ -p ANOTHER_SECRET_ENV_
ANSWER=42
TOKEN=very secret string
VALUE=0
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_
VAR=abc
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:
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dump-env-1.1.0.tar.gz
.
File metadata
- Download URL: dump-env-1.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.7.3 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12574e9aaf17b1b2150285748af29492636b915f3a17d8383448aa49686fe70e |
|
MD5 | 4294d8cd21a01773c7a042bda36a51a0 |
|
BLAKE2b-256 | b60dea0df66ebd40db2bd56af9ee3cb4ee760f7c88eca67a9124e8701026e46d |
File details
Details for the file dump_env-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: dump_env-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.11 CPython/3.7.3 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afe4dc9f19cd993a1bdfeacdfe5a04e8efccae270e47b2c3a3269a14cdd72c40 |
|
MD5 | 7d0dce9a6dcc6660430c4787f20e1f28 |
|
BLAKE2b-256 | a9315ead599399e0b71b0252d38a9bb3fa42c18c119ba8135149588772971c0f |