Skip to content

Commit b006c21

Browse files
authored
Merge pull request #91 from 1Password/sdk-core/2024-08-06-d16c23e9
Release v0.1.0-beta.13
2 parents bfb4627 + 3acdf73 commit b006c21

File tree

18 files changed

+186
-33
lines changed

18 files changed

+186
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ To use the 1Password Python SDK in your project:
5757
3. Install the 1Password Python SDK in your project:
5858

5959
```bash
60-
pip install git+ssh://[email protected]/1Password/[email protected].9
60+
pip install git+ssh://[email protected]/1Password/[email protected].13
6161
```
6262

6363
4. Use the Python SDK in your project:

example/example.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ async def main():
1515
integration_version="v1.0.0",
1616
)
1717

18+
vaults = await client.vaults.list_all()
19+
async for vault in vaults:
20+
print(vault.title)
21+
items = await client.items.list_all(vault.id)
22+
async for item in items:
23+
print(item.title)
24+
1825
# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.
1926
value = await client.secrets.resolve("op://vault/item/field")
2027
print(value)
@@ -50,7 +57,10 @@ async def main():
5057
details=None,
5158
),
5259
],
53-
sections=[ItemSection(id="", title=""), ItemSection(id="totpsection", title="")],
60+
sections=[
61+
ItemSection(id="", title=""),
62+
ItemSection(id="totpsection", title=""),
63+
],
5464
)
5565
created_item = await client.items.create(to_create)
5666

@@ -64,7 +74,6 @@ async def main():
6474
else:
6575
print(f.details.content.code)
6676

67-
6877
# Retrieve an item from your vault.
6978
item = await client.items.get(created_item.vault_id, created_item.id)
7079

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_shared_library_data_to_include():
4343

4444
setup(
4545
name="onepassword",
46-
version="0.1.0-beta.12",
46+
version="0.1.0-beta.13",
4747
author="1Password",
4848
description="The 1Password Python SDK offers programmatic read access to your secrets in 1Password in an interface native to Python.",
4949
url="https://github.com/1Password/onepassword-sdk-python",

src/onepassword/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .types import * # noqa F403
55
from .secrets import Secrets
66
from .items import Items
7+
from .vaults import Vaults
78

89

910
import sys
@@ -14,6 +15,7 @@
1415
"Client",
1516
"Secrets",
1617
"Items",
18+
"Vaults",
1719
"DEFAULT_INTEGRATION_NAME",
1820
"DEFAULT_INTEGRATION_VERSION",
1921
]

src/onepassword/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
from .defaults import new_default_config
55
from .secrets import Secrets
66
from .items import Items
7+
from .vaults import Vaults
78

89

910
class Client:
1011
secrets: Secrets
1112
items: Items
13+
vaults: Vaults
1214

1315
@classmethod
1416
async def authenticate(cls, auth, integration_name, integration_version):
@@ -23,6 +25,7 @@ async def authenticate(cls, auth, integration_name, integration_version):
2325

2426
authenticated_client.secrets = Secrets(client_id)
2527
authenticated_client.items = Items(client_id)
28+
authenticated_client.vaults = Vaults(client_id)
2629
authenticated_client._finalizer = weakref.finalize(
2730
cls, _release_client, client_id
2831
)

src/onepassword/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import platform
22

33
SDK_LANGUAGE = "Python"
4-
SDK_VERSION = "0010012"
4+
SDK_VERSION = "0010013"
55
DEFAULT_INTEGRATION_NAME = "Unknown"
66
DEFAULT_INTEGRATION_VERSION = "Unknown"
77
DEFAULT_REQUEST_LIBRARY = "net/http"

src/onepassword/items.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# AUTO-GENERATED
22
from .core import _invoke
33
from json import loads
4-
from .types import Item
4+
from .iterator import SDKIterator
5+
from .types import Item, ItemOverview
56

67

78
class Items:
@@ -20,14 +21,14 @@ async def create(self, params):
2021
{
2122
"clientId": self.client_id,
2223
"invocation": {
23-
"name": "Create",
24+
"name": "ItemsCreate",
2425
"parameters": {
25-
"params": params.dict(),
26+
"params": params.model_dump(by_alias=True),
2627
},
2728
},
2829
}
2930
)
30-
return Item(**loads(response))
31+
return Item.model_validate_json(response)
3132

3233
async def get(self, vault_id, item_id):
3334
"""
@@ -37,15 +38,15 @@ async def get(self, vault_id, item_id):
3738
{
3839
"clientId": self.client_id,
3940
"invocation": {
40-
"name": "Get",
41+
"name": "ItemsGet",
4142
"parameters": {
42-
"vault_id": vault_id,
4343
"item_id": item_id,
44+
"vault_id": vault_id,
4445
},
4546
},
4647
}
4748
)
48-
return Item(**loads(response))
49+
return Item.model_validate_json(response)
4950

5051
async def put(self, item):
5152
"""
@@ -55,14 +56,14 @@ async def put(self, item):
5556
{
5657
"clientId": self.client_id,
5758
"invocation": {
58-
"name": "Put",
59+
"name": "ItemsPut",
5960
"parameters": {
60-
"item": item.dict(),
61+
"item": item.model_dump(by_alias=True),
6162
},
6263
},
6364
}
6465
)
65-
return Item(**loads(response))
66+
return Item.model_validate_json(response)
6667

6768
async def delete(self, vault_id, item_id):
6869
"""
@@ -73,11 +74,32 @@ async def delete(self, vault_id, item_id):
7374
{
7475
"clientId": self.client_id,
7576
"invocation": {
76-
"name": "Delete",
77+
"name": "ItemsDelete",
7778
"parameters": {
78-
"vault_id": vault_id,
7979
"item_id": item_id,
80+
"vault_id": vault_id,
8081
},
8182
},
8283
}
8384
)
85+
86+
async def list_all(self, vault_id):
87+
"""
88+
List all items
89+
"""
90+
response = await _invoke(
91+
{
92+
"clientId": self.client_id,
93+
"invocation": {
94+
"name": "ItemsListAll",
95+
"parameters": {
96+
"vault_id": vault_id,
97+
},
98+
},
99+
}
100+
)
101+
response_data = loads(response)
102+
103+
objects = [ItemOverview.model_validate(data) for data in response_data]
104+
105+
return SDKIterator(objects)

src/onepassword/iterator.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import asyncio
2+
from typing import AsyncIterator, Iterable, TypeVar
3+
4+
T = TypeVar("T")
5+
6+
7+
class SDKIterator(AsyncIterator[T]):
8+
def __init__(self, obj: Iterable[T]):
9+
self.obj = obj
10+
self.index = 0
11+
self.lock = asyncio.Lock()
12+
13+
def __aiter__(self) -> AsyncIterator[T]:
14+
return self
15+
16+
async def __anext__(self) -> T:
17+
async with self.lock:
18+
if self.index >= len(self.obj):
19+
raise StopAsyncIteration
20+
21+
next_obj = self.obj[self.index]
22+
self.index += 1
23+
return next_obj
1.59 MB
Binary file not shown.
-2.63 MB
Binary file not shown.

0 commit comments

Comments
 (0)