Debugging#
Using the Python debugger#
You can configure Litestar to drop into the Python Debugger when an exception occurs. This can be configured in different ways:
- Configuring
Litestar
with thepdb_on_exception
option app = Litestar(pdb_on_exception=True)
- Running your app with the CLI and using the
--pdb
flag litestar run --pdb
- Using the
LITESTAR_PDB
environment variable LITESTAR_PDB=1
Debugging with an IDE#
You can easily attach your IDEs debugger to your application, whether you’re running it via the CLI or a webserver like uvicorn.
Intellij / PyCharm#
Using the CLI#
Create a new debug configuration via
Run
>Edit Configurations
Select
Module name
option and set it tolitestar
Add the
run
parameter and optionally additional parameters you want to pass to the CLIRun your application in the debugger via
Run
>Debug Litestar
Important
Breakpoints inside route handlers might not work correctly when used in conjunction
with the --reload
and --web-concurrency
parameters. If you want to use the
CLI while making use of these options, you can attach the debugger manually to the
running uvicorn process via Run
> Attach to process
.
Using uvicorn#
Create a new debug configuration via
Run
>Edit Configurations
Select
Module name
option and set it touvicorn
Add the
app:app
parameter (or the equivalent path to your application object)Run your application in the debugger via
Run
>Debug Litestar
VS Code#
Using the CLI#
- Add a new debugging configuration via
Run
>Add configuration
- Add a new debugging configuration via
- From the
Select a debug configuration
dialog, selectModule
- From the
- Enter
litestar
as the module name
- Enter
- In the opened JSON file, alter the configuration as follows:
{ "name": "Python: Litestar app", "type": "python", "request": "launch", "module": "litestar", "justMyCode": true, "args": ["run"] }
- Run your application via the debugger via
Run
>Start debugging
- Run your application via the debugger via
Using uvicorn#
- Add a new debugging configuration via
Run
>Add configuration
- Add a new debugging configuration via
- From the
Select a debug configuration
dialog, selectModule
- From the
- Enter
uvicorn
as the module name
- Enter
- In the opened JSON file, alter the configuration as follows:
{ "name": "Python: Litestar app", "type": "python", "request": "launch", "module": "uvicorn", "justMyCode": true, "args": ["app:app"] }
- Run your application via the debugger via
Run
>Start debugging
- Run your application via the debugger via