December 1, 2023

Manage Environment Variables in Python Projects

I find I have to tell developers (sometimes even developers with a few years’ experience) again and again how to properly manage environment variables - so I write this simple post so that I can just send a link.

Don’ts

Don’ts: DO NOT ever write the keys in your code - you will forget and push the keys to your repo.

Dos

Do one of the followings (I use OPENAI_API_KEY as an example and my preferred way is method 2):

  1. use export command
  1. use .env file

Method 2 above is my preferred way especially when you have many environment variables to manage.

PS. The featured image for this post is generated using HiddenArt.ai.