Skip to content

Remove initialize and close from the Client class #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
goloroden opened this issue May 30, 2025 · 1 comment · May be fixed by #90
Open
2 tasks done

Remove initialize and close from the Client class #85

goloroden opened this issue May 30, 2025 · 1 comment · May be fixed by #90
Assignees

Comments

@goloroden
Copy link
Member

goloroden commented May 30, 2025

What is this task about?

Right now, the Python client requires you to call initialize explicitly. We should get rid of this and ensure that the client is usable, as described in the documentation.

What needs to be done to complete this task?

  • Fix the behavior to work as described in the documentation
  • Ensure that creating a new client and running ping immediately works
@atstaeff atstaeff self-assigned this May 30, 2025
@atstaeff atstaeff linked a pull request Jun 6, 2025 that will close this issue
@atstaeff
Copy link
Contributor

atstaeff commented Jun 6, 2025

Initial Situation

Previously, the client required explicit calls to initialize() and close() to manage the connection lifecycle. This put the responsibility on the user to ensure proper setup and teardown, increasing the risk of mismanagement, especially in the presence of exceptions.

Insight

Managing resources manually is error-prone and not aligned with modern asynchronous Python best practices. Python provides built-in support for context managers (async with) that can ensure safe and automatic setup and teardown of resources — even when exceptions occur.

Consequence

The initialize() and close() methods have been removed.
Instead, the client now implements the asynchronous context manager protocol (__aenter__ and __aexit__), which automates connection handling.

Usage now requires wrapping the client in an async with block:

async with Client() as client:
    await client.do_something()

## Benefits
Simplifies the API

Reduces the chance of forgetting to close resources

Makes the code more robust and readable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants