TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Follow publication

Member-only story

Keep your code secure by using environment variables and env files

Mike Huls
TDS Archive
Published in
6 min readNov 1, 2021
Let’s enrich this beautiful environment with some variables (image by Rob Morton on Unsplash)

Your code needs to connect to a database. For this it needs a password to that database. How can you use this password in your app in such a way that you can both connect to the database and keep the password private?

This article shows you how to use an env file in your code. This file stores all of our confidential information. It can be loaded once so you have access to all of your private information like passwords anywhere in your app. In this article we’ll use Python to illustrate the workings of an env file but the principle applies for all programming languages.

At the end of this article you’ll:

  • understand the advantages of using environment variables
  • understand how environment variables work
  • understand how we can load environment variables from an env file

Let’s code!

1. Why use environment variables?

There are two main reasons to use environment variable files:
1. safety
2. flexibility

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Mike Huls
Mike Huls

Written by Mike Huls

I write about interesting programming-related things: techniques, system architecture, software design and how to apply them in the best way. — mikehuls.com

Responses (2)

Write a response