1Password / connect-sdk-python

Python SDK for 1Password Connect
https://developer.1password.com/docs/connect
MIT License
200 stars 30 forks source link

Async await support #62

Closed volodymyrZotov closed 1 year ago

volodymyrZotov commented 1 year ago

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.

codecov-commenter commented 1 year ago

Codecov Report

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

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

:exclamation: 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 ```diff @@ 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](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [src/onepasswordconnectsdk/async\_client.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay9hc3luY19jbGllbnQucHk=) | `65.35% <65.35%> (ø)` | | | [src/onepasswordconnectsdk/serializer.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay9zZXJpYWxpemVyLnB5) | `67.74% <67.74%> (ø)` | | | [src/onepasswordconnectsdk/client.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay9jbGllbnQucHk=) | `63.37% <77.19%> (-3.79%)` | :arrow_down: | | [src/onepasswordconnectsdk/utils.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay91dGlscy5weQ==) | `90.90% <90.90%> (ø)` | | | [src/onepasswordconnectsdk/connect.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay9jb25uZWN0LnB5) | `93.75% <93.75%> (ø)` | | | [src/onepasswordconnectsdk/errors.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL29uZXBhc3N3b3JkY29ubmVjdHNkay9lcnJvcnMucHk=) | `100.00% <100.00%> (ø)` | | | [src/tests/test\_client\_items.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3Rlc3RzL3Rlc3RfY2xpZW50X2l0ZW1zLnB5) | `100.00% <100.00%> (ø)` | | | [src/tests/test\_client\_vaults.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3Rlc3RzL3Rlc3RfY2xpZW50X3ZhdWx0cy5weQ==) | `100.00% <100.00%> (ø)` | | | [src/tests/test\_config.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3Rlc3RzL3Rlc3RfY29uZmlnLnB5) | `100.00% <100.00%> (ø)` | | | [src/tests/test\_connect.py](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3Rlc3RzL3Rlc3RfY29ubmVjdC5weQ==) | `100.00% <100.00%> (ø)` | | ... and [5 files with indirect coverage changes](https://app.codecov.io/gh/1Password/connect-sdk-python/pull/62/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jillianwilson commented 1 year ago

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