App Factory Reference
There are two app factories in the active Python package. Use create_app when you are building a downstream service from the reusable quickstart package. Use create_spaps_app only when running or testing the concrete Sweet Potato SPAPS service.
create_app
Defined in
packages/python-server-quickstart/src/spaps_server_quickstart/app_factory.py.
def create_app(
*,
settings_loader,
api_router,
additional_middlewares=None,
enable_request_logging=True,
request_logger_name=None,
enable_spaps_auth=None,
auth_exempt_paths=None,
enable_cors=None,
extra_cors_origins=None,
run_startup_checks=None,
):
...| Parameter | Use |
|---|---|
settings_loader | Zero-argument callable returning a BaseServiceSettings subclass |
api_router | Root APIRouter for the consuming service |
additional_middlewares | Extra Starlette/FastAPI middlewares added after shared middleware |
enable_spaps_auth | Overrides settings.spaps_auth_enabled |
auth_exempt_paths | Adds paths beyond the required auth-exempt defaults |
run_startup_checks | Defaults to enabled except in env="test" |
create_spaps_app
Defined in packages/python-server-quickstart/src/spaps_server_quickstart/spaps_app.py.
from spaps_server_quickstart.spaps_app import create_spaps_app
app = create_spaps_app()It does more than create_app: imports all domain models, creates DatabaseResources, runs SPAPS-specific startup invariants, mounts every product router, installs response envelopes, rate limiting, security headers, and CORS, then stores db_resources and settings on app.state.
Common Mistakes
Do not use create_spaps_app as a generic downstream-service factory. It mounts the full SPAPS
domain surface.
- Running startup checks in tests without isolating required secrets.
- Adding middleware in a place that changes CORS preflight behavior.
- Forgetting to close external auth clients when SPAPS auth middleware is enabled.