Environment variables in Python .env

posted in: AI | 0

I see a lot of code examples with important keys in them or greyed out in screen shots. Newish to Python there had to be a better way and there is… the .env file.

Place a .env file in your project

image

Add all the key/value pairs of secret/important things – I’ve mainly used it for my Open AI, Azure Open AI etc keys

image

Load the variables:

image

And then you can get them as needed

image