Skip to content

Commit 6092003

Browse files
committed
docs: update CLAUDE.md for self-managed connection pool
1 parent be0c090 commit 6092003

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

CLAUDE.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,22 @@ The `DeezerBaseClient.get_data()` method handles two important edge cases:
314314

315315
### Connection Pooling
316316

317-
For production use, pass an `httpx.AsyncClient` to avoid creating a new connection for every request:
317+
`DeezerBaseClient` self-manages its own `httpx.AsyncClient`, created lazily on first request. No external setup needed:
318318

319319
```python
320-
async with httpx.AsyncClient() as http:
321-
client = DeezerGQLClient(arl="your_arl", http_client=http)
322-
# All requests reuse the same connection pool
320+
# Recommended: use as async context manager
321+
async with DeezerGQLClient(arl="your_arl") as client:
322+
me = await client.get_me()
323+
324+
# Or manage lifecycle manually
325+
client = DeezerGQLClient(arl="your_arl")
326+
try:
327+
me = await client.get_me()
328+
finally:
329+
await client.close()
323330
```
324331

325-
If no `http_client` is provided, the base client creates (and closes) a throwaway `httpx.AsyncClient` per request. This works but is inefficient for high-volume usage like library syncs.
332+
An external `http_client` can still be passed for advanced use cases (e.g., sharing a pool across multiple clients), but the caller is then responsible for closing it.
326333

327334
### Audiobook ID Checking
328335

@@ -418,15 +425,16 @@ Use comments only to explain "why", not "what". Reserve inline comments for comp
418425

419426
### Test Structure
420427

421-
Tests are organized into four layers:
428+
Tests are organized into five layers:
422429

423430
| Layer | Tests | What's validated |
424431
| ------------------------- | ----- | ---------------------------------------------------------------------------------- |
425432
| **Client setup** | 3 | Import, instantiation with ARL, presence of all generated methods |
433+
| **Lifecycle** | 3 | close() on internal client, skip close on external client, context manager |
426434
| **Auth flow** (mocked) | 5 | JWT acquisition, token reuse, refresh on expiry, cookie domain, text/plain parsing |
427435
| **Error handling** | 5 | HTTP errors, invalid JSON, missing data key, GraphQL errors, success path |
428-
| **Model smoke tests** | 62 | One per query/mutation — fixture parses correctly with key fields accessible |
429436
| **Audiobook ID checking** | 2 | Batch alias query returns correct subset; empty input returns empty set |
437+
| **Model smoke tests** | 62 | One per query/mutation — fixture parses correctly with key fields accessible |
430438

431439
### Auth Flow Tests
432440

0 commit comments

Comments
 (0)