Skip to content

Add support for async close on http client#315

Merged
logan-twilio merged 2 commits intomainfrom
issue-314-async-client-close
May 4, 2026
Merged

Add support for async close on http client#315
logan-twilio merged 2 commits intomainfrom
issue-314-async-client-close

Conversation

@logan-twilio
Copy link
Copy Markdown
Contributor

Fixes #314

Adds close() and async context manager support to AsyncClient and ClientBase, giving users a reliable way to release the underlying aiohttp.ClientSession without depending on __del__.

New usage patterns:

# Async context manager
async with stytch.Client(project_id=..., secret=...) as client:
    await client.magic_links.email.login_or_create(...)

# Explicit close (e.g. in a FastAPI lifespan)
client = stytch.Client(project_id=..., secret=...)
try:
    ...
finally:
    await client.close()

close() is a no-op if the session was externally provided or never created. The existing __del__ fallback is preserved for cases where neither pattern is used.

@logan-twilio logan-twilio requested a review from a team as a code owner May 4, 2026 17:10
@logan-twilio logan-twilio requested a review from akorn-twilio May 4, 2026 17:10
@logan-stytch logan-stytch force-pushed the issue-314-async-client-close branch from 3523c42 to b319cb4 Compare May 4, 2026 17:12
@logan-twilio logan-twilio merged commit d553738 into main May 4, 2026
16 checks passed
@logan-twilio logan-twilio deleted the issue-314-async-client-close branch May 4, 2026 20:45
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.

Unclosed client session <aiohttp.client.ClientSession object at 0x10cdfe510> ERROR:asyncio:Unclosed client session

4 participants