Reputation: 69
Say I have some API-key in my project that I don't wanna share into git repository, then I have to use environment variables. Now, why shouldn't I blatantly set the environmental variable on my local machine (like PATH) instead of making .env file and downloading python-dotenv library to my project for the sake of doing actually the same thing?
Upvotes: 2
Views: 7595
Reputation: 144
.env
file is just manner to store this variables in file that can use packages for example dotenv to read as an os.environ
varaible. so in short it is manner of storage of configuration.
many times your gitignore will have .env
thus users can store the API key with .env
file on local machine to help ease of use and ensuring dont accidently leave api keys within committed git files
if you just do a bear os.environ['API-KEY'] = 'stuff'
within code it will store in commited git file (and env variables are there within a run of python process, not their permanently between sessions, thus why storing in file is preferred)
with this there are types of way to store configuration dynaconf is a great package and package shows many of the other types of configuration files
Upvotes: 1