Detecting and configuring a FastAPI project for debugging #5136
-
For the Python extension for VS Code we are starting to add support to automatically detect and configure debugging for select web frameworks (you can already configure debugging manually; this is just a nicety). We would like to have support for FastAPI in this situation, but we need to know two things:
If there are any specific guidelines you can provide that would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Can you look at requirements/setup.py or project toml files? Or |
Beta Was this translation helpful? Give feedback.
-
This is awesome! Here are the heuristics: FileThe main file would be:
After that, the next most common options would be:
And other possible but probable quite less common options:
ObjectInside of that file, there would normally be an object The symbol/class Another possible name for that object would be ConfigThe JSON object at {
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"${fileToPythonModule}:${appObject}"
],
"jinja": true
} Where And where You already have a launch debug template, @Kludex implemented it, the main thing I would think could be improved automatically is detecting that file and that variable. Normally the app object is at the top level, there are not many cases where it needs a factory function, so in most cases, it should be statically analyzable (I would think). Just the object that is an instance of the |
Beta Was this translation helpful? Give feedback.
This is awesome!
Here are the heuristics:
File
The main file would be:
main.py
After that, the next most common options would be:
app/main.py
app.py
And other possible but probable quite less common options:
app/app.py
api.py
app/api.py
api/main.py
Object
Inside of that file, there would normally be an object
app
. It would be an instance of the classFastAPI()
. The instantiation would normally be in that same file.The symbol/class
FastAPI
comes fromfastapi.FastAPI
(exported in the__init__.py
of the package), and is defined infastapi.applications.FastAPI
.Another possible name for that object would be
api
, but probably not too common.Config
The JSON object at
.vscode/launch.json
…