How to load .env file for different environments in python?

Viewed 2494

I have three .env files for local, dev and prod environment and I have to load specific environments file while doing deployment for that server i.e If am doing DEV deployment then dev .env file should load all.

1 Answers

You can use the pip module python-dotenv to load .env files.
Here's what you need to do:

from dotenv import load_dotenv

load_dotenv(some_path)

Now the vars in the env file located at some_path can be used with os.getenv

Related