claude-code-sdk-python/examples
Dickson Tsai 5f8351fce9
Some checks are pending
Lint / lint (push) Waiting to run
Test / test (3.10) (push) Waiting to run
Test / test (3.11) (push) Waiting to run
Test / test (3.12) (push) Waiting to run
Test / test (3.13) (push) Waiting to run
Make streaming implementation trio-compatible (#84)
## Summary
- Replace asyncio.create_task() with anyio task group for trio
compatibility
- Update client.py docstring example to use anyio.sleep
- Add trio example demonstrating multi-turn conversation

## Details
The SDK already uses anyio for most async operations, but one line was
using asyncio.create_task() which broke trio compatibility. This PR
fixes that by using anyio's task group API with proper lifecycle
management.

### Changes:
1. **subprocess_cli.py**: Replace asyncio.create_task() with anyio task
group, ensuring proper cleanup on disconnect
2. **client.py**: Update docstring example to use anyio.sleep instead of
asyncio.sleep
3. **streaming_mode_trio.py**: Add new example showing how to use the
SDK with trio

## Test plan
- [x] All existing tests pass
- [x] Manually tested with trio runtime (created test script that
successfully runs multi-turn conversation)
- [x] Linting and type checking pass

🤖 Generated with [Claude Code](https://claude.ai/code)
2025-07-22 23:31:42 -07:00
..
quick_start.py cost_usd -> total_cost_usd in example 2025-06-25 15:18:52 -04:00
streaming_mode.py Improve examples 2025-07-19 19:57:17 -07:00
streaming_mode_ipython.py Improve examples 2025-07-19 19:57:17 -07:00
streaming_mode_trio.py Make streaming implementation trio-compatible (#84) 2025-07-22 23:31:42 -07:00