FAQ & Troubleshooting¶
Installation¶
pip install faster-api-web succeeds but import FasterAPI fails¶
Make sure you are importing with the correct capitalisation:
The PyPI package name is faster-api-web; the Python package directory is FasterAPI.
ImportError: TestClient requires httpx¶
uvloop is not being used¶
uvloop is only installed as an optional extra and only activates on Linux.
Running the app¶
uvicorn main:app --reload — app not found¶
Make sure your file is named main.py and it contains app = Faster().
Port already in use¶
Swagger UI (/docs) shows no routes¶
Routes must be registered before the first request. If you use include_router,
call it before uvicorn starts, not inside a handler.
Request handling¶
422 Unprocessable Entity on valid-looking input¶
Check:
1. Content-Type: application/json header is set.
2. The JSON matches the struct field types exactly (e.g. int vs str).
3. Required fields are present and not null.
Path parameter is always None¶
Path parameters must appear in the URL pattern:
Query parameter not received¶
Check the URL encoding. Spaces should be %20 or +.
File upload returns 422¶
Make sure the client sends multipart/form-data and the field name matches:
Middleware¶
CORS preflight fails¶
Add CORSMiddleware before any routes are hit:
app.add_middleware(
CORSMiddleware,
allow_origins=["https://yourfrontend.com"],
allow_methods=["*"],
allow_headers=["*"],
)
Middleware order matters¶
Middleware is applied in reverse registration order. Add more-specific middleware last (it will run first):
app.add_middleware(CORSMiddleware, ...) # outer (registered first)
app.add_middleware(TimingMiddleware) # inner (registered last)
Dependencies¶
Depends() result is not cached between calls¶
By default, Depends is cached per request. If you see it called multiple
times, check that you're passing the same callable (not a lambda):
Circular dependency¶
FasterAPI does not detect circular Depends() chains. If you get a RecursionError,
look for A → B → A dependency cycles.
Database¶
asyncpg / SQLAlchemy session errors in tests¶
Each test must use its own session. Share a session factory, not a session.
RuntimeError: Task attached to a different loop¶
Do not share asyncio objects (like connections) between asyncio.run() calls.
Use on_startup / on_shutdown to manage the lifecycle within a single event loop.
Performance¶
Throughput is lower than expected¶
- Enable uvloop:
pip install uvicorn[standard]orpip install faster-api-web[all]. - Use multiple workers:
uvicorn main:app --workers 4. - Profile with
py-spyorcProfileto find bottlenecks. - Check if database queries are the bottleneck (add
EXPLAIN ANALYZE).
High memory usage¶
- Check for memory leaks in background tasks.
- Ensure database connections are properly released (
async with session). - Profile with
tracemallocormemray.
OpenAPI / Swagger UI¶
Swagger UI is blank or shows errors¶
- Visit
/openapi.jsondirectly and check for JSON syntax errors. - Ensure
docs_urlandopenapi_urlare not set toNone. - Check browser console for CORS errors if the UI is hosted separately.
Response schema is missing or wrong¶
Make sure the return type annotation is a msgspec.Struct or a supported primitive
type. dict return types generate a generic object schema.
WebSockets¶
WebSocket connection immediately closes¶
The handler must await ws.accept() before sending or receiving data.
WebSocket 4004 error¶
No WebSocket route matched the requested path. Check path spelling and trailing slashes.
Getting help¶
- GitHub Issues: github.com/FasterApiWeb/FasterAPI/issues
- Source code: Browse
FasterAPI/on GitHub. - Changelog: See CHANGELOG for recent changes.