Categories
Development

Python environment variables

For my Python applications I want to use variables from an .env file, so I can store this in a local file for configuration flexibility.

Example:

OPENAI_API_KEY=mySecretKey
import os
from dotenv import load_dotenv

# .env-Datei laden
load_dotenv()
print("OPENAI_API_KEY: " + os.getenv("OPENAI_API_KEY"))
python envexample.py
OPENAI_API_KEY: mySecretKey

Leave a Reply

Your email address will not be published. Required fields are marked *