Repository navigation
feat(client): add close and context manager support to Client and Asy… - #169
Conversation
|
@tharropoulos review this when you have time |
haydenhoang
left a comment
There was a problem hiding this comment.
Thanks, this looks good.
One request: the docs still show the old way of closing the client, so please update them to use the new API:
README.md, in the "Async usage" example: replace await client.api_call.aclose() with async with typesense.AsyncClient({...}) as client:
The same client.api_call.aclose() pattern appears in:
examples/async_collection_operations.pyexamples/async_conversation_streaming.pyexamples/async_export_streaming.py
It might also be worth a short note in the README that a caller-supplied http_client is left open, so the caller has to close it.
Fine to do in a follow-up PR if you prefer.
tharropoulos
left a comment
There was a problem hiding this comment.
Thanks for picking this up.
One change requested inline, on the __aenter__ return type. Hayden's docs request still stands as well, since README.md and the three async examples still call client.api_call.aclose().
…from __enter__/__aenter__
Updated README.md and the three async examples (examples/async_collection_operations.py, examples/async_conversation_streaming.py, and examples/async_export_streaming.py) to use async with typesense.AsyncClient(...) as client: instead of await client.api_call.aclose(), and added a note in README.md that a caller-supplied http_client is left open for the caller to close (commit 77ec039). |
Closes #168
Summary
Exposes
close()/aclose()and context manager methods (with/async with) directly onClientandAsyncClientso users can manage connection pool lifecycles without reaching intoclient.api_call.Changes
__aenter__,__aexit__, andaclosetoAsyncClientinsrc/typesense/async_/client.py, delegating toself.api_call.aclose().__enter__,__exit__, andclosetoClientinsrc/typesense/sync/client.py, delegating toself.api_call.close().tests/client_test.pyverifyingclose()/aclose(), context manager exit behavior, and preservation of caller-suppliedhttp_clientinstances.Testing
py_compile.Clientlifecycle againsthttpx.Client.is_closedand asyncAsyncClientdelegation withAsyncMock.run-unasync.py --check,ruff,mypy, andpytest).