Skip to content

Add close() and context manager support to Client and AsyncClient#145

Merged
gtsystem merged 2 commits into
gtsystem:masterfrom
chassing:add-close-and-context-manager-support
Jul 9, 2026
Merged

Add close() and context manager support to Client and AsyncClient#145
gtsystem merged 2 commits into
gtsystem:masterfrom
chassing:add-close-and-context-manager-support

Conversation

@chassing

@chassing chassing commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #144

The sync Client had no way to close the underlying httpx connection pool, leaking file descriptors until process exit. The async AsyncClient had close() but lacked aclose() and async context manager support.

  • Add close(), __enter__, __exit__ to sync Client
  • Add aclose(), __aenter__, __aexit__ to AsyncClient
  • Add close() to GenericSyncClient
  • Update docs with a "Closing the client" section
  • Update README examples to use context managers
  • Bump version to 0.22.0

Usage

# Sync
with Client() as client:
    pod = client.get(Pod, name="my-pod")

# Async
async with AsyncClient() as client:
    pod = await client.get(Pod, name="my-pod")

Test plan

  • Added test_close and test_context_manager for sync Client
  • Added test_close, test_aclose, test_async_context_manager for AsyncClient
  • Full test suite passes (189 tests)

The sync Client had no way to close the underlying httpx connection pool,
leaking file descriptors. The async AsyncClient had close() but lacked
aclose() and async context manager support.

- Add close(), __enter__, __exit__ to sync Client
- Add aclose(), __aenter__, __aexit__ to AsyncClient
- Add close() to GenericSyncClient
- Add tests for both sync and async close/context manager
- Update docs and README examples
- Bump version to 0.22.0

Fixes gtsystem#144
@gtsystem

gtsystem commented Jul 8, 2026

Copy link
Copy Markdown
Owner

CI is failing. Can you run uv lock and commit the changes to the lock file?

@gtsystem
gtsystem merged commit a22e84d into gtsystem:master Jul 9, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync Client missing close() / context manager — httpx connection pool leaks

2 participants