Skip to content

Commit 1b2c5bd

Browse files
cubehouseclaude
andcommitted
docs: how to see every HTTP request via httpx logger
Add a "Debugging" section to README.md and a fourth cookbook recipe showing the standard logging incantation for httpx + httpcore, plus a note that cached responses bypass the transport so won't show up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e40e4bc commit 1b2c5bd

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,38 @@ with ThemeParks() as tp:
187187
`RateLimitError` is a subclass of `APIError`, so the order of the `except`
188188
blocks matters if you want to handle 429 specially.
189189

190+
## Debugging — see every HTTP request
191+
192+
The SDK is built on `httpx`, which has a built-in logger. Turn it on to see
193+
every outbound request and response status:
194+
195+
```python
196+
import logging
197+
logging.basicConfig(level=logging.INFO)
198+
logging.getLogger("httpx").setLevel(logging.DEBUG)
199+
200+
from themeparks import ThemeParks
201+
with ThemeParks() as tp:
202+
tp.entity("75ea578a-adc8-4116-a54d-dccb60765ef9").live()
203+
```
204+
205+
Output:
206+
207+
```
208+
INFO httpx HTTP Request: GET https://api.themeparks.wiki/v1/entity/75ea578a-adc8-4116-a54d-dccb60765ef9/live "HTTP/1.1 200 OK"
209+
```
210+
211+
For raw byte-level traces (TLS handshake, header bytes, etc.), also enable
212+
the `httpcore` logger:
213+
214+
```python
215+
logging.getLogger("httpcore").setLevel(logging.DEBUG)
216+
```
217+
218+
> **Note:** requests served from the in-memory cache do **not** appear in
219+
> `httpx` logs — they're returned before the transport is touched. To see
220+
> every call as a network round-trip while debugging, pass `cache=False`.
221+
190222
## Caching
191223

192224
The default client caches `GET` responses in-memory with sensible per-endpoint

docs/cookbook.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,44 @@ async def main() -> None:
159159

160160
asyncio.run(main())
161161
```
162+
163+
## Recipe 4 — See every HTTP request the SDK makes
164+
165+
The SDK is built on `httpx`, which has a built-in logger. Enable it before
166+
constructing the client to see every outbound request and response status
167+
in real time:
168+
169+
```python
170+
import logging
171+
logging.basicConfig(level=logging.INFO)
172+
logging.getLogger("httpx").setLevel(logging.DEBUG)
173+
174+
from themeparks import ThemeParks
175+
176+
with ThemeParks() as tp:
177+
tp.destinations.list()
178+
tp.entity("75ea578a-adc8-4116-a54d-dccb60765ef9").live()
179+
```
180+
181+
Output:
182+
183+
```
184+
INFO httpx HTTP Request: GET https://api.themeparks.wiki/v1/destinations "HTTP/1.1 200 OK"
185+
INFO httpx HTTP Request: GET https://api.themeparks.wiki/v1/entity/75ea578a-adc8-4116-a54d-dccb60765ef9/live "HTTP/1.1 200 OK"
186+
```
187+
188+
For raw byte-level traces (TLS handshake, header bytes, retries, connection
189+
reuse) also enable the `httpcore` logger:
190+
191+
```python
192+
logging.getLogger("httpcore").setLevel(logging.DEBUG)
193+
```
194+
195+
Tip: requests served from the in-memory cache do **not** appear in `httpx`
196+
logs — they are returned before the transport is touched. While debugging,
197+
pass `cache=False` to force every call to hit the network:
198+
199+
```python
200+
with ThemeParks(cache=False) as tp:
201+
...
202+
```

0 commit comments

Comments
 (0)