Configuration Overview
Environment variables are loaded differently depending on your environment:- Local Development: Variables are loaded from a
.envfile usingpython-dotenv - Production (Heroku): Variables are set using
heroku config:setand managed through Heroku’s config system
When
FLASK_ENV=development, the application automatically loads variables from .env. In production, set variables directly in your hosting environment.Required Variables
These environment variables must be set for the application to function:YAHOO_CLIENT_ID
Your Yahoo Developer application’s Client ID
- Visit Yahoo Developer Network
- Create or select your application
- Find the Client ID in your app settings
YAHOO_CLIENT_SECRET
Your Yahoo Developer application’s Client Secret
- Same location as Client ID in Yahoo Developer settings
- May need to click “Show Secret” to reveal the value
FLASK_SECRET_KEY
Secret key used for Flask session encryption and security
Optional Variables
FLASK_ENV
Determines the application environment mode
development- Enables debug mode, auto-reload, and loads.envfileproduction- Disables debug features, optimized for performance
FLASK_ENV=development:
- Auto-loads
.envfile:
- Enables debug mode:
Environment File Example
Create a.env file in your project root for local development:
Setting Variables by Environment
Local Development
- Copy the example file:
- Edit
.envwith your values:
- Verify variables are loaded:
Heroku Production
- Set individual variables:
- Set multiple variables at once:
- View all config variables:
- Remove a variable:
Complete Environment Variables Table
| Variable | Type | Required | Default | Description |
|---|---|---|---|---|
YAHOO_CLIENT_ID | string | Yes | None | Yahoo Developer application Client ID |
YAHOO_CLIENT_SECRET | string | Yes | None | Yahoo Developer application Client Secret |
FLASK_SECRET_KEY | string | Yes | "dev-key" | Secret key for session encryption (never use default in production) |
FLASK_ENV | string | No | "production" | Application environment (development or production) |
Security Best Practices
Use strong, random secrets
Use strong, random secrets
Generate cryptographically secure random strings for
FLASK_SECRET_KEY:Never commit secrets to version control
Never commit secrets to version control
Always use Verify nothing sensitive is tracked:
.gitignore to exclude sensitive files:Use different secrets per environment
Use different secrets per environment
Never reuse the same
FLASK_SECRET_KEY across environments:- Development: One secret key
- Staging: Different secret key
- Production: Different secret key
Rotate credentials regularly
Rotate credentials regularly
Periodically update your credentials:
- Generate new Yahoo OAuth credentials
- Update environment variables
- Test the application
- Delete old credentials from Yahoo Developer
Validate environment on startup
Validate environment on startup
Add validation to catch missing variables early:
Troubleshooting
Variables not loading in development
- Check
FLASK_ENVis set todevelopment:
- Verify
.envfile exists in project root:
- Check
.envfile format:
KeyError when accessing variables
If you seeKeyError: 'YAHOO_CLIENT_ID':
Next Steps
Local Development
Set up your development environment
Heroku Deployment
Deploy to production