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

Async await support #62

Merged
merged 24 commits into from
Sep 8, 2023
Merged

Async await support #62

merged 24 commits into from
Sep 8, 2023

Conversation

volodymyrZotov
Copy link
Contributor

@volodymyrZotov volodymyrZotov commented Jan 6, 2023

Resolves #58

This PR adds the ability to use the client library in async way.

To initialize an async client you can pass is_async: bool flag to new_client(url: str, token: str, is_async: bool = False) function.

async def main():
    async_client = new_client(CONNECT_HOST, CONNECT_TOKEN, True)
    item = await async_client.get_item_by_title("Test", "dslxntic63k5spe34o556n4hio") # retrieve item asynchronously 
    print(item)
    await async_client.session.aclose() # close the client gracefully when you are done

asyncio.run(main())

By default, NON-async client is initialized.

Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2023

Codecov Report

Patch coverage: 83.30% and project coverage change: +2.58% 🎉

Comparison is base (56a6f3e) 74.38% compared to head (feeeb87) 76.97%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
+ Coverage   74.38%   76.97%   +2.58%     
==========================================
  Files          22       28       +6     
  Lines        1667     1928     +261     
==========================================
+ Hits         1240     1484     +244     
- Misses        427      444      +17     
Files Changed Coverage Δ
src/onepasswordconnectsdk/async_client.py 65.35% <65.35%> (ø)
src/onepasswordconnectsdk/serializer.py 67.74% <67.74%> (ø)
src/onepasswordconnectsdk/client.py 63.37% <77.19%> (-3.79%) ⬇️
src/onepasswordconnectsdk/utils.py 90.90% <90.90%> (ø)
src/onepasswordconnectsdk/connect.py 93.75% <93.75%> (ø)
src/onepasswordconnectsdk/errors.py 100.00% <100.00%> (ø)
src/tests/test_client_items.py 100.00% <100.00%> (ø)
src/tests/test_client_vaults.py 100.00% <100.00%> (ø)
src/tests/test_config.py 100.00% <100.00%> (ø)
src/tests/test_connect.py 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
@volodymyrZotov volodymyrZotov marked this pull request as ready for review January 9, 2023 15:39
@jillianwilson
Copy link
Contributor

Looks good overall but can you update the readme with info about using async

Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
Signed-off-by: volodymyrZotov <volodymyr.zotov@gmail.com>
Copy link
Member

@edif2008 edif2008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on working on this complex task. So far it looks solid.

I will say that it's a bit tricky to easily compare the two clients and see the key differences in the current state.

With that, I have a couple of comments / questions:

  • Is it possible to do a benchmark and see if the async client if faster than the normal one? Asking to see if it does a significant advantage to the user.
  • Would it be better to split the async and sync client into separate files? I feel like it would help readability (for this review at least) and maintainability. Same goes for splitting the tests for async and sync clients.

Copy link
Member

@edif2008 edif2008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review: ➖

Not needed since the main part of this PR is to 'duplicate' the functionality for an async client. By checking the diffs between the two clients, I can confirm that they have the same functionality. Therefore, folks who will use the async client only need to tweak the code related to getting the async client. The rest will remain the same.

Also, the tests made for the async client should give us the confidence that the async client works as expected.

Code review: ✅

This looks good to be merged.
I've left some nitpick comments that shouldn't block this from being merged.

@volodymyrZotov volodymyrZotov merged commit f9087fc into main Sep 8, 2023
@volodymyrZotov volodymyrZotov deleted the async_await_support branch September 8, 2023 16:45
@volodymyrZotov volodymyrZotov mentioned this pull request Sep 8, 2023
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 to support async operations
4 participants