Configuration
Flaskteroids keeps application configuration organized by environment, with separate database configuration, encrypted credentials, and boot-time initializers.
Application boot
A generated application boots through config/environment.py:
wsgi.py exposes that application to Flask and WSGI servers:
Application-wide configuration lives in config/application.py:
from flaskteroids.application import Application as FlaskteroidsApplication
from config.boot import ROOT
class Application(FlaskteroidsApplication):
root = ROOT
def configure(self, config):
config.load_defaults('0.1')
config.x.payments.provider = 'stripe'
config.load_defaults() pins the framework defaults used when the application was generated. Updating Flaskteroids does not silently opt the application into defaults introduced by a later release.
Environments
The environment is selected in this order:
FLASKTEROIDS_ENVFLASK_ENVdevelopment
The selected file under config/environments/ is applied after application-wide configuration:
# config/environments/production.py
import os
def configure(config):
config.eager_load = True
config.consider_all_requests_local = False
config.require_master_key = True
config.action_mailer.perform_deliveries = True
config.active_job.broker_url = os.environ.get(
'CELERY_BROKER_URL', config.active_job.broker_url
)
The current environment is available from the application:
Environment variables are read explicitly in configuration code. Flaskteroids does not automatically map arbitrary SMTP, job, or application environment variables into settings.
Database configuration
Database connections are configured in config/database.yml, separately from application configuration:
default: &default
adapter: sqlite3
pool: 5
development:
<<: *default
database: storage/development.sqlite3
test:
<<: *default
database: storage/test.sqlite3
production:
adapter: postgresql
database: my_application_production
Values can reference environment variables with ${NAME} or ${NAME:-default}:
production:
adapter: postgresql
database: ${DATABASE_NAME}
username: ${DATABASE_USER:-postgres}
password: ${DATABASE_PASSWORD}
DATABASE_URL uses the following precedence:
- When present, it overrides connection values from the selected environment.
- An explicit
urlentry indatabase.ymltakes precedence overDATABASE_URL. - Without either URL, Flaskteroids constructs the connection URL from the selected settings.
Encrypted credentials
Shared credentials are encrypted in config/credentials.yml.enc. The local key is stored in config/master.key, which is excluded from Git and container images.
Edit or display credentials with:
Environment-specific credentials use the --environment option:
These commands create:
When environment-specific credentials exist, they replace the shared credentials for that environment. Encryption keys are resolved from FLASKTEROIDS_MASTER_KEY first and then from the corresponding key file.
Credentials are available through the application:
application.credentials.secret_key_base
application.credentials.payments.api_key
application.credentials['payments']['api_key']
secret_key_base signs sessions, CSRF tokens, and password-reset tokens. Production should set config.require_master_key = True so boot fails when credentials cannot be decrypted.
Initializers
Files in config/initializers/*.py run once during application initialization, in filename order and inside the application context. Use initializers to configure external libraries:
# config/initializers/payments.py
from flaskteroids import application
from payments import Client
application.extensions['payments'] = Client(
api_key=application.credentials.payments.api_key
)
Boot order
Flaskteroids initializes an application in this order:
- Select the environment.
- Apply
config/application.pyconfiguration. - Apply
config/environments/<environment>.py. - Load
config/database.ymland credentials. - Initialize framework components.
- Run files in
config/initializers/. - Finish route and application setup.
This separation keeps boot behavior predictable and application configuration explicit.