Skip to content

feat: async context manager support for Python SDK connection cleanup - #915

Closed
laurentketterle-hub wants to merge 1 commit into
MetroLogic:mainfrom
laurentketterle-hub:feat/async-context-manager-sdk
Closed

laurentketterle-hub wants to merge 1 commit into
MetroLogic:mainfrom
laurentketterle-hub:feat/async-context-manager-sdk

Conversation

@laurentketterle-hub

Copy link
Copy Markdown

Description

Adds async context manager support (__aenter__/__aexit__) to the Python SDK for proper connection cleanup.

Changes

  • __aenter__/__aexit__: Async context manager methods that ensure:

    • Connection is established on entry (if not already connected)
    • Connection is properly closed on exit (including on exceptions)
    • No redundant reconnection if already connected
  • __enter__/__exit__: Sync context manager methods for non-async usage

  • Tests: Comprehensive test coverage for:

    • Async connect/close lifecycle
    • Already-connected optimization
    • Exception propagation with cleanup
    • Sync context manager path
  • CI: Python SDK CI workflow with pytest-asyncio across Python 3.9-3.12

Usage

# Async usage
async with FluxaPayClient() as client:
    result = await client.get_balance()

# Sync usage  
with FluxaPayClient() as client:
    result = client.get_balance()

Closes #796

- Adds __aenter__/__aexit__ for async context manager support
- Adds __enter__/__exit__ for sync context manager support
- Ensures proper connection cleanup on context exit
- Skips reconnect if already connected
- Adds comprehensive tests for both sync and async paths
- Adds Python SDK CI workflow

Closes MetroLogic#796
@laurentketterle-hub

Copy link
Copy Markdown
Author

Automated CI refresh: no activity for 7 days. Closing and reopening to trigger CI re-run.

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.

[SDK] Python SDK lacks async context manager support for connection cleanup

2 participants