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 environment 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:
Related
You might also be interested in:
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.2.0.tar.gz
.
File metadata
- Download URL: dump-env-1.2.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.7 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b9ee7a8afe2a8194a712d12a925cc54f0b3178833491fdced5dcb6f68b56c60 |
|
MD5 | 9bdf10f03429fced7ab95a45eec0d4dc |
|
BLAKE2b-256 | 9fd574192bbf1511d28390b8b047970920b1d0eac890a8238ec7cdfb1527efe0 |
File details
Details for the file dump_env-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: dump_env-1.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.7.7 Darwin/18.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca26f6d87a33418adb794338e748a0d3507014e3388250077c696e8c96634562 |
|
MD5 | 10721003ff04c10090e2b8189b154ecc |
|
BLAKE2b-256 | cd79af6861bc0a33db57759b0e118d353ea7471bf0e01429fc7ad796298c83d0 |