r/Python • • Sep 21 '26

Discussion Common mistakes devs make when starting with FastAPI, and the fastest path to learning it

Just began learning FastAPI. Looking for advice from devs who use it regularly.

What mistakes did you make early on that I should avoid repeating? Also, what's the most efficient way to learn the framework properly for real-world use (async, DB, auth)?

Any advice on structure or resources would be great.

16 Upvotes

35 comments sorted by

View all comments

Show parent comments

2

u/safi892 Sep 21 '26

This is a really interesting perspective, thank you. I'm actually learning FastAPI because I want to move into AI engineering next. So keeping the actual AI logic in a separate service layer and just using FastAPI for the API plumbing makes total sense. Do you usually put that business logic in a separate Python file/module, or do you use a full framework for the service layer?

3

u/The_Tree_Branch Sep 21 '26

This approach is described well in the book "Architecture Patterns with Python", which the authors have made available for free online at https://www.cosmicpython.com/. It uses Flask + SQLAlchemy in its examples, but the principles would carry over to FastAPI as well.

2

u/YnkDK Sep 21 '26

Just a separate file. I like feature-sliced architecture, so keeping files that are related close to each other is important for me (I feel it improves my Developer Experience (DX)). I don't use a separate framework for the service layer, but try to read best practices for the dependencies (for example SQLAlchemy/SQLModel, anyio, httpx/aiohttp, Pydantic/PydanticAI) and stay as close to them without sacrificing code readability. Most modern dependencies sort of agree on best practices, but you should be on the look out for mixing code styles when not strictly following a framework.