Geek Logbook

Tech sea log book

Why is it important to know what Environment Variables are?

While learning to avoid hardcoding some keys in my projects, I found the concept of environment variables. I’ve found this interesting article about this topic here in medium: An Introduction to Environment Variables and How to Use Them.

The main reason we have to use Environment Variables in our projects is, as Jim Said:

“The primary use case for environment variables is to limit the need to modify and re-release an application due to changes in configuration data.”

How to use environment variables.

The primary benefit of setting environment variables is not changing the source code when changing the application’s configuration. I suppose this practice helps us avoid one of the best-known antipatterns: Hard Coding.

The candidates to use as environment variables are those whose data change infrequently, and the application logic treats them like constants.

When you add environmental variables to your project code, it’s expected that you don’t want to share this part of the source code with the rest of the world. But it will be necessary if somebody wants to run the project to set them. 

With a proper configuration of enviroment variables, sho will be hiding this information from the rest of the world. Therefore, the file where the variables are located may be ignored when the code goes from your local machine to the repository, whether public or private. For example, in Git, you add the environment variables, usually located in a .env file, to the .gitignore before pushing this code to the cloud where the code is located.

Interesting Python articles.

1 – Making Use of Environment Variables in Python

2 – Working with Environment Variables in Python

3 – How to Set and Get Environment Variables in Python

General Article about Environment variables.

An Introduction to Environment Variables and How to Use Them

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *.