On this page
article
Load .env File
Load local environment variables from .env.
Category: python-dotenv
Problem
Load local environment variables from .env.
Solution
load_dotenv()
api_key = os.environ['API_KEY']
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path