Skip to content
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

Add external session and context manager to Client #90

Merged
merged 7 commits into from
Jul 26, 2023
Merged

Conversation

atimin
Copy link
Member

@atimin atimin commented Jul 26, 2023

Closes #71

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • CHANGELOG.md have been updated (for bug fixes / features / docs)

What kind of change does this PR introduce?

Feature

What is the current behavior?

We create a new session for each HTTP request. This is very inefficient.

What is the new behavior?

To avoid breaking compatibility, I've added an additional argument to constructor to pass an external aihttp.Session. A user can also use a context manager:

    async with Client(url, api_token=api_token) as client:
        bucket = await client.create_bucket("bucket-1", exist_ok=True)
        await bucket.info()

Does this PR introduce a breaking change?

No

Other information:

@atimin atimin marked this pull request as draft July 26, 2023 12:58
@atimin atimin marked this pull request as ready for review July 26, 2023 19:17
@atimin atimin merged commit 89b1cc1 into main Jul 26, 2023
22 checks passed
@atimin atimin deleted the external_session branch July 26, 2023 19:17
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.

Feature: Optimize session management
1 participant