www.infolytx.com
FastAPI - The Good, the Bad and the Ugly - Infolytx
Excerpt
## The Bad ### 1. Crowded main file In FastAPI, everything is tied to the ``` FastAPI app ``` . So, your ``` main.py ``` file can very easily become very crowded. Here is an example. … ### 2. No singleton in Dependency Injection Dependency Injection in FastAPI does no support ``` singleton ``` instances, according to this Github thread, but it supports single instance for each HTTP request. You either have to create singleton classes yourself or use a different DI library. ## The Ugly ### Request Validation My worst experience while working with FastAPI was handling request validations. It uses validation from ``` Pydantic ``` , and there is, to my knowledge, no straight forward way to pass down a validation message from the point of validation to the response. You have make do with whatever message is passed down by
Source URL
https://www.infolytx.com/fast-api-gbu/Related Pain Points
Code organization becomes unwieldy as projects scale
5FastAPI tends to centralize everything in the main.py file, causing crowding and maintenance issues. Teams need to manually create dedicated files for exception handlers and router inclusion to maintain code organization.
Request validation error messages are not customizable
5FastAPI uses Pydantic for validation, but there is no straightforward way to pass custom validation messages from the validation point to the API response, forcing developers to use whatever generic messages Pydantic provides.
Dependency Injection lacks native singleton support
4FastAPI's DI system doesn't natively support singletons, forcing teams to manually manage shared resources through singleton classes or adopt third-party DI libraries.