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
+34-13Lines changed: 34 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,25 +16,40 @@ 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
29
+
<Note>
30
+
This code is for local development only and must not be included in production
31
+
deployments.
32
+
</Note>
33
+
23
34
```python
24
35
import debugpy
25
36
26
37
host, port = debugpy.listen(("0.0.0.0", 52509)) # Static port for consistent debugging
27
38
print(f"✅ Debugpy is listening on {host}:{port}", flush=True)
28
39
```
29
40
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.
41
+
<Note>
42
+
A **static port** (`52509`) is used so the IDE knows which port to connect to.
43
+
Update the `launch.json` configuration to match this port before starting the
44
+
debugger.
45
+
</Note>
31
46
32
-
### 2. Update `nitric.yaml`
47
+
### 3. Update `nitric.yaml`
33
48
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.
49
+
Modify the `start` command to include an auto-reloader and ensure Python does not use frozen modules, which can interfere with `debugpy`:
35
50
36
51
```yaml
37
-
name: message-board
52
+
name: my-project
38
53
services:
39
54
- basedir: ''
40
55
match: services/*.py
@@ -49,9 +64,12 @@ runtimes:
49
64
args: {}
50
65
```
51
66
52
-
> This configuration restarts the service on file changes and includes the necessary flags for debugging compatibility.
67
+
<Note>
68
+
This configuration restarts the service on file changes and includes the
69
+
necessary flags for debugging compatibility.
70
+
</Note>
53
71
54
-
### 3. Configure `launch.json` in VS Code
72
+
### 4. Configure `launch.json` in VS Code
55
73
56
74
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
75
@@ -85,14 +103,17 @@ To create or update the launch.json file:
85
103
}
86
104
```
87
105
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.
106
+
<Note>
107
+
Ensure the `port` matches the value used in the `debugpy.listen()` call. If
108
+
the port changes in the code, update it here as well.
109
+
</Note>
89
110
90
-
### 4. Running the debugger
111
+
### 5. Running the debugger
91
112
92
-
Start your nitric service with `nitric start`and start the debugger.
113
+
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