Documentation
Pfg Fastapi Serve
Reference docs for pydantic-fixturegen.
pfg fastapi serve
Capabilities
pfg fastapi serve spins up a deterministic mock server that mirrors your FastAPI routes but responds with data generated by fixturegen. It is powered by build_mock_app, so every response is stable under the selected seed and respects presets/config.
Typical use cases
- Hand front-end teams a mock API that never drifts from your schema.
- Demo new endpoints without touching real services.
- Provide QA with a deterministic mock that still exercises validators and dependency overrides.
Inputs & outputs
- Target: FastAPI app import path (
module:attr). - Server: uses Uvicorn to run a local server at
--host/--port.
Flag reference
--host: host/IP to bind (default127.0.0.1).--port: port to bind (default8000).--seed: override the deterministic seed for generated responses.--dependency-override original=override: repeatable option to replace dependencies before building the mock app (same syntax as the smoke command).
Example workflows
Launch a mock server on port 8050
pfg fastapi serve app.main:app \
--host 0.0.0.0 --port 8050 --seed 7 \
--dependency-override "app.auth.get_user=fakes.allow_all"
Sample output
[fastapi_mock_start] host=0.0.0.0 port=8050 seed=7
INFO: Started server process [93845]
INFO: Waiting for application startup.
INFO: Application startup complete.
Example response (curl http://localhost:8050/users/1)
{
"id": "52b8e8b2-3a27-4561-b5b9-6e44f1b27d88",
"email": "avery@example.org",
"created_at": "2025-11-08T12:00:00Z"
}
Local-only mock with dependency override
pfg fastapi serve app.main:app \
--host 127.0.0.1 --port 9000 \
--dependency-override "app.services.billing:get_client=fakes.billing_client"
Runs the server on localhost and swaps the billing client with a fake implementation so outbound calls are never made.
Operational notes
- Requires the
fastapiextra plusuvicorn. If the dependency is missing, fixturegen raisesDiscoveryErrorinstructing you to installpydantic-fixturegen[fastapi]. - The CLI logs
fastapi_mock_startevents so you can capture host/port metadata. - Override paths accept
module.attrormodule:attrsyntax. Both original and override must resolve to callables. - Stop the server with
Ctrl+C; since the command blocks the terminal, run it undernohup/tmuxwhen sharing with teammates.