A tool inspired by dotenvx, but easier to install in python projects.
You can load it and invoke your python scripts / apps using the action run
:
pydotenvx run -f $path-to-dotenv-file -- python script.py
You can load more than one file. In case of conflicting keys, the last value overrides the previous. Some examples are:
pydotenvx run -f $file1 $file2 $file3 -- python script.py
pydotenvx run -f $folder_with_multiple_files/*.env -- python script.py
In case you want to test the final values, you may run the action list
:
pydotenvx list -f $file1 $file2 $file3
Your .env
file should look like this:
a = "1"
b = "2"
Parsing is currently strict and expects values surrounded by "quotes".
Compared to dotenv
and its port python-dotenv
, I prefer the choices from dotenvx
:
- support for multiple dotenv files
- executable tool instead of library code
I have conflicting thoughts about encryption, so it's currently not supported - and may not ever be.
I also prefer to use this tool during development and something else to inject environment variables on deployments.
This is just nice.
Not to trash on python-dotenv
, but I've seen multiple problems from invoking it in code:
- inflexibility: an app may require a file named
.env
, forbidding developers from managing .env files in different ways - implicit: an app may try to load a ".env", with different effects if it's not there
- coupling: an app may not work without a
.env
file
These problems can be mitigated with careful planning,
but I believe that the normal usage of dotenvx
or pydotenvx
will naturally avoid some of these issues.
I still thank the developers of python-dotenv
for creating a useful tool that I used in many projects.
Other features are currently not supported - there's not a plan to allow or block them.
Development is currently based on poetry=1.6.1
, as its the package manager I'm more used to.
You may format, lint and test the code using make all
.
Generated by my-python-template, created by Duarte Pompeu.