How to Easily Debug a FastAPI App in VSCode

preview_player
Показать описание

Debugging a FastAPI app in VSCode is tricky because the code is run via a tool like `uvicorn` , and you typically interact with the API via curl statements or a browser. In this video, I’ll show you how to setup debugging for your FastAPI app.

🔖 Chapters:
0:00 Intro
0:20 Code Explanation
2:22 What is Debugging?
3:36 Debugging A FastAPI Application
6:38 Starting The Debugging
7:25 Components Of The Debugger
11:41 Example of Debugging
17:42 Breakpoints and Logpoints
20:19 General Debugging Tips
21:48 Automatically Open Up a Browser
22:35 Final Thoughts

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

I usually use the debug terminal instead of watch statements. The expressions I want to watch are usually to complex to fit into the watch section so setting a breakpoint and running the statement in the debug terminal is shorter.

In general having access to a complete python REPL in the debug terminal is such a powerful feature :)

maviecestbon
Автор

Not only a great tutorial about debugging FastAPI, but about debugging in general! I learned a lot, thanks!

chrisgeishauser
Автор

Just a heads up: you should probably disable automatic title translation for both regular videos and shorts. This video, for example, shows up as “01 03 DEBUG FASTAPI” on my country (Portugal). The same has been happening to your shorts. This title is mostly gibberish and sounds like a placeholder for the actual title English speakers must be seeing.

Necas
Автор

I also find very useful to use the debug console. After I reaching a breakpoint you can try expressions or inspect/call object methods directly in the debug console.

jschwindt
Автор

This is really a great tutorial. I always test my program in hard way. You've shown me a better way to do this
Thank you

teddyperera
Автор

After I have found the breakpoint() function it's been wonderful to stop the code and try different things to understand some unusual behaviour. But This video has great tips for debugger. Thanks.

magnus
Автор

Perfect timing, how did you know? Literally doing this right now.

demolazer
Автор

Happy New Year dear Arjan, with many great videos like 2024 !!!

tedlazar
Автор

Please make a playlist about what to do and not to do in production-grade API building.

souravbanerjee
Автор

Very helpful as always! Thank you Arjan

conneyk
Автор

So excited for this video! THANK YOU! Watching now

ChaseAdams-so
Автор

Iam looking for this video all over youtube thanks for this video

jaivenkatesh
Автор

Conditional breakpoints are super useful. I use them in Pycharm a lot. I didnt know about all those extra breakpoint types though, I dont think Pycharm has them. The break only on x number of hits, or "wait for other breakpoint" functionality.

Seems really useful.

tswdev
Автор

Happy New Year / gelukkig nieuwjaar 🎉 and thank you for the great video! I would like to suggest the VS Code extension REST Client. It’s great for sending GET/POST requests and presenting the qry and response in a clear format.

difegam
Автор

I use debugger not often, but it's really helpfull for me to dive deeper inside the object structure for example, which I met throughout debugging process. This helps to find some interesting things related to the object structure etc. However as far as I know and heard, not many developers actully used debugger in their developing process. They argue this by saying that their code no complex and they fully understands what the code should do. I partially agree with them, but sometimes it's hard to understand where is an error is occurred in the code.

Arjan, what is your thoughts on this? How often you use (used) debugging in your developing routine? 🙂

MrVernuk
Автор

where is the github repo for this example fast API that you showed in the video?

sanyahmed
Автор

Hi Arjan, I wish you all the best for 2025. And thanks a lot for the debugging tipps. I’m also a great fan of using the debugging features provided by my IDE. Perhaps you can add a video that shows how to debug a script which is called in a piped Linux cmdline chain like cat data | ./myscript.py -a | ./myscript.py -b
It works with debug py but it’s tricky cause I need two debug sessions in my IDE. But I admit that is might be an edge case.

uwegenosdude
Автор

This is a dap protocol, and you can use this monster in any editors. Vim or emacs can do the same things.

kapustinalexander
Автор

Easier to write unit test that directly call your FastAPI endpoints with a temporary db or other store under it. Also you can call endpoints directly as functions for some types of testing. I don't see why you want to debug under uvicorn if you goal is debugging your fastapi logic itself. Are you trying to debug uvicorn somehow?

serenditymuse
Автор

I already have a .venv before I started debugging, but upon the launch.json, it is asking me for a Python interpreter before I can start debugging, so instead of typing, Find... Browse your file system to find a Python interpreter, but it cannot seem to find the .venv/bin/python already created, manually typing the path of .venv keeps saying it cannot find .venv/bin/python that was created in the first place.

MrNiceseb
welcome to shbcf.ru