You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 20, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: docs/guides/python/debugging.mdx
+29-13Lines changed: 29 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,13 @@ This guide will walk you through setting up local debugging for Nitric applicati
16
16
17
17
Debugging serverless-style applications can be challenging due to the way functions are triggered by events. For Python, we can use [`debugpy`](https://github.com/microsoft/debugpy) to connect a debugger to the service while it runs.
18
18
19
-
### 1. Modify the Python entry point
19
+
### 1. Add debugpy to our project
20
+
21
+
```bash
22
+
uv add debugpy
23
+
```
24
+
25
+
### 2. Modify the Python entry point
20
26
21
27
Add the following lines to the top of the service file (e.g., `services/api.py`). This starts a debug server that the IDE can attach to.
22
28
@@ -27,14 +33,18 @@ host, port = debugpy.listen(("0.0.0.0", 52509)) # Static port for consistent de
27
33
print(f"✅ Debugpy is listening on {host}:{port}", flush=True)
28
34
```
29
35
30
-
> A **static port** (`52509`) is used so the IDE knows which port to connect to. Update the `launch.json` configuration to match this port before starting the debugger.
36
+
<Note>
37
+
A **static port** (`52509`) is used so the IDE knows which port to connect to.
38
+
Update the `launch.json` configuration to match this port before starting the
39
+
debugger.
40
+
</Note>
31
41
32
-
### 2. Update `nitric.yaml`
42
+
### 3. Update `nitric.yaml`
33
43
34
-
Modify the `start` command to include an auto-reloader and ensure Python does not use frozen modules, which can interfere with `debugpy`, E.g.
44
+
Modify the `start` command to include an auto-reloader and ensure Python does not use frozen modules, which can interfere with `debugpy`:
35
45
36
46
```yaml
37
-
name: message-board
47
+
name: my-project
38
48
services:
39
49
- basedir: ''
40
50
match: services/*.py
@@ -49,9 +59,12 @@ runtimes:
49
59
args: {}
50
60
```
51
61
52
-
> This configuration restarts the service on file changes and includes the necessary flags for debugging compatibility.
62
+
<Note>
63
+
This configuration restarts the service on file changes and includes the
64
+
necessary flags for debugging compatibility.
65
+
</Note>
53
66
54
-
### 3. Configure `launch.json` in VS Code
67
+
### 4. Configure `launch.json` in VS Code
55
68
56
69
VS Code uses a `launch.json` file to define how it should start or attach to a debugging session. In this case, the debugger doesn't launch the application itself—it attaches to the running service that was started manually from the terminal.
57
70
@@ -85,14 +98,17 @@ To create or update the launch.json file:
85
98
}
86
99
```
87
100
88
-
> Ensure the `port` matches the value used in the `debugpy.listen()` call. If the port changes in the code, update it here as well.
101
+
<Note>
102
+
Ensure the `port` matches the value used in the `debugpy.listen()` call. If
103
+
the port changes in the code, update it here as well.
104
+
</Note>
89
105
90
-
### 4. Running the debugger
106
+
### 5. Running the debugger
91
107
92
-
Start your nitric service with `nitric start`and start the debugger.
108
+
Start your nitric service with `nitric start`, in the Terminal, both the Nitric runtime output and the debugpy listener output will be visible, including the active debug port.
0 commit comments