4 Tips for Building a Production-Ready FastAPI Backend

preview_player
Показать описание
In this video, I’ll talk about 4 things that you typically won’t find in most FastAPI tutorials online. These tips are really useful, especially if you want to create a backend that’s used in a production setting.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

Social channels:

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund

🔖 Chapters:
0:00 Intro
1:57 #1 Split into separate routers
5:22 #2 Move operations out of the endpoint functions
15:58 #3 Optimize the way you deploy your application
22:51 #4 Control access
26:00 Final thoughts

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

Here's my vote for a oauth flow video, thanks for this one!

johanboekhoven
Автор

In the router, you can use response_model (which takes a pydantic model you define), and then when you return the database item, FastAPI does the JSON conversion for you.

SpoonOfDoom
Автор

Quick tip 💡Always declare functions used by Depends(...) as async. FastAPI runs synchronous dependencies in a separate thread with asyncio.to_thread, which considerably slows down your application when the request rate is high due to the overhead of spawning a new thread!

thefatalis
Автор

Would love to see an authentication flow for FastAPI tutorial !

iflipphone
Автор

Thanks Arjan. I like that you always set up more complete example projects and talk about the real-world use cases and considerations. Security is an important aspect that is not easily understood so an Oauth/JWT vid would be cool.

eltreum
Автор

OAuth flow video will be great! Thanks for all your crème de la crème content.

mosheglobus
Автор

Been working on a CLI to scaffold out my microservice architecture, defaulting to FastAPI-based services.

I’m glad to see I’m on the right track. There were definitely a few points I will start implementing from now on.

skysaville
Автор

I'd love videos that address scalability, multi-tenant architecture and caching strategies for applications that work with larger amounts of data in the backend - like when there is a time series and maybe some complicated statistical computation retrieved from a database. I find that too many tutorials focus on the eCommerce bubble or - if they deal with more complicated data structures - they focus on the presentation layer. For example, I would love to see how you design a backend for the plotly/Dash dashboards that can handle large amounts of data.

devilasks
Автор

The FastAPI videos are awesome! One thing I haven't found much at all about and I find myself frustrated with a lot is setting up FastAPI with SQLModel using more complex databases with many-to-many relationships and properly using TYPE_CHECKING and other things to avoid circular imports when breaking the application into separate components. A video covering this would be GREATLY appreciated! Thanks again for all the work you do!

CodeGearMonkey
Автор

7:32, one remark:
- instead of doing **db_item.__dict__, you can do model_validate(_json) to "cast" the (I surmise) SQLAlchemy object from the db to your Pydantic type. (Assuming you are using Pydantic >2, otherwise you can do .from_orm)

I also see patterns where you inject a db and pass it to the crud method quite often. Why not define a db interface, create a class that implements that IF and construct/use it here? e.g. db.read_item(item_id). You could still use dependency injection and also completely change the impelmentation, as long as you adhere to the interface. Curious to hear your thoughts on it.

erikvanraalte
Автор

The video I have been waiting for!! Thanks Arjan

conconmc
Автор

Good on pulumi to sponsor this video. Just recently stumbled on this channel and it’s really good. I’ll definitely be giving a pulumi a try very soon

rembautimes
Автор

Hi thanks for this excellent video. A video on the folder structure of a fastapi project would be great. Thank you for your Fastapi videos, they help me make progress.

nulops
Автор

One small correction (if I dare say) to 4:22, fastAPI does care how you name your functions when you enable swagger coz your function sort of become the description of the API endpoint.


Love your videos btw

pramodjingade
Автор

Hi Arjan, thanks for the grest video. I also think that having a look at SQLModel makes sense. Both FastAPI and SQLModel where created by Sebastian Ramirez amd the purpose of SQLModel is exactly to not have to struggle with Pydantic models and sqlalchemy (database mmodels). An SQLModel class inherits bith from pydantic and sqlalchemy. So you would have only one Item object in the project.

oszsdnb
Автор

Was looking for this yesterday! thank you

ishandandekar
Автор

Love your content as always Arjan. Can you do a video about how to implement multi-tenancy in fast-api, especially regarding the difference in services each tenant wil use? So which folder stucture and which design patterns for difference in price calculation or language etc. Might be a nice challenge for an architect like you ;)

inspiredbyrd
Автор

I really appreciate the fastapi content. :)

kslader
Автор

Great video, very helpful! Thank you Arjan!

Very interested in a video on setting up OAuth (specifically behind a corporate VPN) or asynchronous task queues (e.g., with Celery and Flower).

mathijsdejong
Автор

I really really want to see how you would approach this same example, but using SQLModel, which integrates FastAPI and sqlalchemy

baldpolnareff