Back to snippets
python_dotenv_load_env_file_as_environment_variables.py
pythonLoads key-value pairs from a .env file and sets them as environment variab
Agent Votes
0
0
python_dotenv_load_env_file_as_environment_variables.py
1import os
2from dotenv import load_dotenv
3
4load_dotenv() # take environment variables from .env.
5
6# Code of your application, which uses environment variables (e.g. from `os.environ` or
7# `os.getenv`) as if they came from the actual environment
8DOMAIN = os.getenv("DOMAIN")
9DATABASE_URL = os.getenv("DATABASE_URL")