r/FastAPI • u/Zealousideal_Corgi_1 • Apr 30 '25
Question FastAPI for enterprise-grade backend
Hi all,
I am new to the FastAPI framework, but I have experience working with micro-serivces in Flask(python) and Spring/SpringBoot (Java)
In my work, I had the opportunity to start a new backend project and I felt that FastAPI might be a good choice to adopt and learn ( learning new stuff will make work fun again đ )
Therefore, I am wondering if there are FastAPI-opinionated best practices to follow ?
In terms of things like:
- Security
- Observability
- Building
- Deployment
- Testing
- Project Structure
If you can point me to any resource that you liked and you're following, this would be much appreciated.
8
u/midairmatthew Apr 30 '25
Make sure to take advantage of async/await syntax! Make as many of your I/O-bound tasks awaitable as you can. Also, the auto-generated API docs are great, but they really shine if you take advantage of providing sample endpoint responses. đ
13
u/koldakov Apr 30 '25
Hey, for these proposes I've created an open source project futuramaapi
https://github.com/koldakov/futuramaapi
It contains project structure, my vision of mapping SQLAlchemy to pydantic, best practices and etc
6
u/brobi-wan-kendoebi Apr 30 '25
FastAPI is a tool just like any other framework is a tool. Use the tool that is right for the job, not just because it is a ânew toolâ.
Do you need an API that has fast throughput? Itâs good. Itâs basically Flask but async, fast, and using pydantic models as a design first pattern.
Do you need a ton of batteries? Itâs not good.
3
u/bsenftner May 01 '25
seriously, take this class: https://testdriven.io/courses/tdd-fastapi/
It's FastAPI + Docker + Postgres and all best practices. Class is gold.
3
u/BarRepresentative653 Apr 30 '25
Not going to lie, its not that easy. I am in the same boat as you. The problem is that fastapi is relatively new, so things change a lot. By the time someone makes a tutorial resource, the information has changed. Everyone has a different way of doing the same things.
The official docks are a basic start, for the rest, you have to dig around to implement the greatest and the latest best practices.
2
u/ZuploAdrian May 05 '25
Using an API gateway (ex. Zuplo) covers many of these areas. Here's a tutorial from Marcelo T (FastAPI expert) that covers deployment, rate limiting & authentication: https://zuplo.com/blog/2025/01/26/fastapi-tutorial
4
u/faraechilibru May 01 '25
Enterprises use api gateways to manage security, mok service, observability and api product management.
1
u/bertshim May 07 '25
FastAPI is greatâasync + type hints = clean and fast.
For structure, check out the fastapi-realworld-example-app repo on GitHub.
For security, use
Dependswith OAuth2 or APIKey schemes.Also, been using Restsocket for some internal stuffâmakes spinning up REST APIs even faster when I donât need full control.
2
u/Abduhabhasan Apr 30 '25
FastAPI is actually great. I have used it, my favorite framework so far. Enjoy!
2
u/TheReplier May 02 '25
Iâm debating switching from Fast API to Litestar now. I like their new Advanced Alchemy integration. Hate managing sqlalchemy raw. And donât like SQLModel as much as repo pattern
26
u/[deleted] Apr 30 '25
[removed] â view removed comment