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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5ee681b
Use httpx library instead of requests
volodymyrZotov Jan 5, 2023
f5d3caf
Extract serialization logic to standalone class
volodymyrZotov Jan 5, 2023
7e286ee
Add AsyncClient methods
volodymyrZotov Jan 6, 2023
c073954
Make tests to use respx library
volodymyrZotov Jan 9, 2023
4eb89b3
Cover AsyncClient with tests
volodymyrZotov Jan 9, 2023
68c04da
Update README with async/await feature
volodymyrZotov Jan 27, 2023
d20201d
Update README
volodymyrZotov Jan 27, 2023
d44f496
Update README.md
volodymyrZotov Aug 15, 2023
39e0636
Address PR comments
volodymyrZotov Aug 15, 2023
8279fae
Merge branch 'main' into async_await_support
volodymyrZotov Aug 15, 2023
93edd50
Update poetry.lock
volodymyrZotov Aug 15, 2023
28422eb
Update USAGE.md with Async client examples
volodymyrZotov Aug 15, 2023
1b453a5
Gracefully close httpx client when delete AsyncClient instance
volodymyrZotov Aug 16, 2023
a9d05e2
Keep Client and AsyncClient backward compatibility
volodymyrZotov Aug 18, 2023
8e99bc6
Add Connect.PathBuilder
volodymyrZotov Aug 18, 2023
f994624
Use PathBuilder to construct the connect url path
volodymyrZotov Aug 18, 2023
cc65238
Merge branch 'main' into async_await_support
volodymyrZotov Sep 5, 2023
feeeb87
Update filter_query comment
volodymyrZotov Sep 5, 2023
a7f5c06
Move path builder class to utils.py
volodymyrZotov Sep 8, 2023
c79a37b
Add test for file content path
volodymyrZotov Sep 8, 2023
a52019e
Use __aexit__ instead of __del__ to properly close async client
volodymyrZotov Sep 8, 2023
56a1c37
Use PathBuilder in get_item_by_id method
volodymyrZotov Sep 8, 2023
818d055
Set default file name as "1password_item_file.txt" in download_file m…
volodymyrZotov Sep 8, 2023
8ae9ffa
Add ability to filter in get_items method
volodymyrZotov Sep 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Check the [Python Connect SDK Example](example/README.md) to see an example of i

```sh
export OP_CONNECT_HOST=<your-connect-host> && \
export OP_CONNECT_TOKEN=<your-connect-token>
export OP_CONNECT_TOKEN=<your-connect-token>
```

3. Use the SDK:
Expand Down
31 changes: 31 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ connect_client_from_env: Client = new_client_from_environment()
connect_client_from_token: Client = new_client(
"{1Password_Connect_Host}",
"{1Password_Connect_API_Token}")

# creates async client
connect_async_client: Client = new_client(
"{1Password_Connect_Host}",
"{1Password_Connect_API_Token}",
True)
```

## Environment Variables
Expand All @@ -32,6 +38,10 @@ connect_client_from_token: Client = new_client(
- `http://localhost:8080` if the Connect server is running in Docker on the same host.
- `http(s)://<ip>:8080` or `http(s)://<hostname>:8080` if the Connect server is running on another host.
- **OP_VAULT** - The default vault to fetch items from if not specified.
- **OP_CONNECT_CLIENT_ASYNC** - Whether to use async client or not. Possible values are:
- True - to use async client
- False - to use synchronous client (this is used by default)


## Working with Vaults

Expand Down Expand Up @@ -136,3 +146,24 @@ CONFIG = Config()

values_object = onepasswordconnectsdk.load(connect_client, CONFIG)
```

## Async client

All the examples above can work using an async client.
```python
import asyncio

# initialize async client by passing `is_async = True`
async_client: Client = new_client(
"{1Password_Connect_Host}",
"{1Password_Connect_API_Token}",
True)

async def main():
vaults = await async_client.get_vaults()
item = await async_client.get_item("{item_id}", "{vault_id}")
# do something with vaults and item
await async_client.session.aclose() # close the client gracefully when you are done

asyncio.run(main())
```
388 changes: 246 additions & 142 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ repository = "https://github.com/1Password/connect-sdk-python"

[tool.poetry.dependencies]
python = "^3.7"
requests = "^2.24.0"
python-dateutil = "^2.8.1"
httpx = "^0.23.3"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
pytest-asyncio = "^0.20.3"
pytest-cov = "^4.0.0"
respx = "^0.20.1"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
Loading