Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit b8ca898

Browse files
committed
Update images and address feedback
1 parent 747f255 commit b8ca898

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

docs/guides/python/debugging.mdx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,40 @@ This guide will walk you through setting up local debugging for Nitric applicati
1616

1717
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.
1818

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
2026

2127
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.
2228

29+
<Note>
30+
This code is for local development only and must not be included in production
31+
deployments.
32+
</Note>
33+
2334
```python
2435
import debugpy
2536

2637
host, port = debugpy.listen(("0.0.0.0", 52509)) # Static port for consistent debugging
2738
print(f"✅ Debugpy is listening on {host}:{port}", flush=True)
2839
```
2940

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>
3146

32-
### 2. Update `nitric.yaml`
47+
### 3. Update `nitric.yaml`
3348

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`:
3550

3651
```yaml
37-
name: message-board
52+
name: my-project
3853
services:
3954
- basedir: ''
4055
match: services/*.py
@@ -49,9 +64,12 @@ runtimes:
4964
args: {}
5065
```
5166
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>
5371
54-
### 3. Configure `launch.json` in VS Code
72+
### 4. Configure `launch.json` in VS Code
5573

5674
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.
5775

@@ -85,14 +103,17 @@ To create or update the launch.json file:
85103
}
86104
```
87105

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>
89110

90-
### 4. Running the debugger
111+
### 5. Running the debugger
91112

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.
93114

94-
![vscode](/docs/images/guides/python-debugging/debugger.png)
115+
![vscode](/docs/images/guides/python-debugging/terminal.png)
95116

96-
In the Terminal, both the Nitric runtime output and the debugpy listener output will be visible, including the active debug port.
117+
Now run the debugger and add breakpoints or watch variables.
97118

98-
In this example, a breakpoint has been hit on line 16 of `message_api.py`, within an HTTP handler for the `/messages` endpoint.
119+
![vscode](/docs/images/guides/python-debugging/debug.png)
216 KB
Loading
264 KB
Loading
-600 KB
Binary file not shown.
76.2 KB
Loading

0 commit comments

Comments
 (0)