FastAPI version 0.140.3 has been released with a targeted optimization that reduces redundant work during OpenAPI schema generation. The key change addresses a performance bottleneck when serializing dependencies into the OpenAPI specification.
- Avoid repeated dependency flattening: Previously, FastAPI would flatten dependencies multiple times during OpenAPI generation, causing unnecessary overhead. This release, via PR #16067 by @tiangolo, refactors the logic to perform dependency flattening only once, caching the result for subsequent use.
- Impact on developers: This improvement is most noticeable in projects with deeply nested dependencies or many shared dependency classes (e.g., database sessions, authentication checks). The OpenAPI generation step becomes faster, reducing time spent on
app.openapi()calls or when the docs UI is first loaded. - No breaking changes: The refactor is purely internal and does not alter any public APIs, dependencies, or runtime behavior. All existing code, including custom dependency classes and
Depends()usage, remains fully compatible.
For developers, this means a smoother development experience when working on large FastAPI applications with complex dependency graphs. Faster OpenAPI generation translates to quicker doc page loading and reduced latency in CI/CD pipelines where OpenAPI schemas are exported or validated.
Source: https://github.com/fastapi/fastapi/releases/tag/0.140.3