Skip to content

Commit

Permalink
Merge pull request #62 from 1Password/async_await_support
Browse files Browse the repository at this point in the history
Async await support
  • Loading branch information
volodymyrZotov authored Sep 8, 2023
2 parents 56a6f3e + 8ae9ffa commit f9087fc
Show file tree
Hide file tree
Showing 14 changed files with 1,362 additions and 669 deletions.
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

0 comments on commit f9087fc

Please sign in to comment.