Skip to content

Commit dbc54b9

Browse files
authored
Merge pull request #145 from 1Password/sdk-core/2025-01-09-571dd93f
Python SDK 0.1.6 RC
2 parents 5aedbae + 65686da commit dbc54b9

File tree

17 files changed

+443
-50
lines changed

17 files changed

+443
-50
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,28 @@ Operations:
8787
- [x] [Create items](https://developer.1password.com/docs/sdks/manage-items#create-an-item)
8888
- [x] [Update items](https://developer.1password.com/docs/sdks/manage-items#update-an-item)
8989
- [x] [Delete items](https://developer.1password.com/docs/sdks/manage-items#delete-an-item)
90+
- [x] Archive items
9091
- [x] [List items](https://developer.1password.com/docs/sdks/list-vaults-items/)
91-
- [x] Add & update tags on items
92+
- [x] Share items
9293
- [x] Generate PIN, random and memorable passwords
9394

9495
Field types:
9596
- [x] API Keys
9697
- [x] Passwords
9798
- [x] Concealed fields
9899
- [x] Text fields
99-
- [ ] Notes
100-
- [x] SSH private keys (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
101-
- [ ] SSH public keys, fingerprint and key type
100+
- [x] Notes
101+
- [x] SSH private keys, public keys, fingerprint and key type (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
102102
- [x] One-time passwords
103103
- [x] URLs
104104
- [x] Websites (used to suggest and autofill logins)
105105
- [x] Phone numbers
106106
- [x] Credit card types
107107
- [x] Credit card numbers
108+
- [x] Emails
109+
- [x] References to other items
110+
- [ ] Address
111+
- [ ] Date / MM/YY
108112
- [ ] Files attachments and Document items
109113

110114
### Vault management

example/example.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,56 @@ async def main():
165165
print(random_password)
166166
# [developer-docs.sdk.python.generate-random-password]-end
167167

168+
await share_item(client, created_item.vault_id, updated_item.id)
169+
168170
# [developer-docs.sdk.python.delete-item]-start
169171
# Delete a item from your vault.
170172
await client.items.delete(created_item.vault_id, updated_item.id)
171173
# [developer-docs.sdk.python.delete-item]-end
172174

175+
## NOTE: this is in a separate function to avoid creating a new item
176+
## NOTE: just for the sake of archiving it. This is because the SDK
177+
## NOTE: only works with active items, so archiving and then deleting
178+
## NOTE: is not yet possible.
179+
async def archive_item(client: Client, vault_id: str, item_id: str):
180+
# [developer-docs.sdk.python.archive-item]-start
181+
# Archive a item from your vault.
182+
await client.items.archive(vault_id, item_id)
183+
# [developer-docs.sdk.python.archive-item]-end
184+
185+
186+
async def share_item(client: Client, vault_id: str, item_id: str):
187+
# [developer-docs.sdk.python.item-share-get-item]-start
188+
item = await client.items.get(vault_id, item_id)
189+
print(item)
190+
# [developer-docs.sdk.python.item-share-get-item]-end
191+
192+
# [developer-docs.sdk.python.item-share-get-account-policy]-start
193+
policy = await client.items.shares.get_account_policy(item.vault_id, item.id)
194+
print(policy)
195+
# [developer-docs.sdk.python.item-share-get-account-policy]-end
196+
197+
# [developer-docs.sdk.python.item-share-validate-recipients]-start
198+
valid_recipients = await client.items.shares.validate_recipients(
199+
policy, ["agilebits.com"]
200+
)
201+
202+
print(valid_recipients)
203+
# [developer-docs.sdk.python.item-share-validate-recipients]-end
204+
205+
# [developer-docs.sdk.python.item-share-create-share]-start
206+
share_link = await client.items.shares.create(
207+
item,
208+
policy,
209+
ItemShareParams(
210+
recipients = valid_recipients,
211+
expireAfter= ItemShareDuration.ONEHOUR,
212+
oneTimeOnly= False,
213+
),
214+
)
215+
216+
print(share_link)
217+
# [developer-docs.sdk.python.item-share-create-share]-end
173218

174219
if __name__ == "__main__":
175220
asyncio.run(main())

src/onepassword/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
for name, obj in inspect.getmembers(sys.modules["onepassword.types"]):
2525
# Add all classes and instances of typing.Literal defined in types.py.
2626
if (
27-
inspect.isclass(obj)
28-
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
29-
) or type(eval(name)) == typing._LiteralGenericAlias:
27+
(
28+
inspect.isclass(obj)
29+
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
30+
)
31+
or isinstance(obj, int)
32+
or type(obj) == typing._LiteralGenericAlias
33+
):
3034
__all__.append(name)

src/onepassword/build_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SDK_BUILD_NUMBER = "0010501"
1+
SDK_BUILD_NUMBER = "0010601"

src/onepassword/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Code generated by op-codegen - DO NO EDIT MANUALLY
22

3+
from __future__ import annotations
34
import weakref
45
from .core import _init_client, _release_client
56
from .defaults import new_default_config
@@ -14,7 +15,9 @@ class Client:
1415
vaults: Vaults
1516

1617
@classmethod
17-
async def authenticate(cls, auth, integration_name, integration_version):
18+
async def authenticate(
19+
cls, auth: str, integration_name: str, integration_version: str
20+
) -> Client:
1821
config = new_default_config(
1922
auth=auth or "",
2023
integration_name=integration_name,

src/onepassword/items.py

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Code generated by op-codegen - DO NO EDIT MANUALLY
22

3-
from .core import _invoke, _invoke_sync
4-
from json import loads
3+
from .core import _invoke
54
from .iterator import SDKIterator
6-
from .types import Item, ItemOverview
5+
from pydantic import TypeAdapter
6+
from .items_shares import ItemsShares
7+
from .types import Item, ItemCreateParams, ItemOverview
78

89

910
class Items:
@@ -13,10 +14,11 @@ class Items:
1314

1415
def __init__(self, client_id):
1516
self.client_id = client_id
17+
self.shares = ItemsShares(client_id)
1618

17-
async def create(self, params):
19+
async def create(self, params: ItemCreateParams) -> Item:
1820
"""
19-
Create a new item
21+
Create a new item.
2022
"""
2123
response = await _invoke(
2224
{
@@ -29,9 +31,11 @@ async def create(self, params):
2931
}
3032
}
3133
)
32-
return Item.model_validate_json(response)
3334

34-
async def get(self, vault_id, item_id):
35+
response = TypeAdapter(Item).validate_json(response)
36+
return response
37+
38+
async def get(self, vault_id: str, item_id: str) -> Item:
3539
"""
3640
Get an item by vault and item ID
3741
"""
@@ -46,9 +50,11 @@ async def get(self, vault_id, item_id):
4650
}
4751
}
4852
)
49-
return Item.model_validate_json(response)
5053

51-
async def put(self, item):
54+
response = TypeAdapter(Item).validate_json(response)
55+
return response
56+
57+
async def put(self, item: Item) -> Item:
5258
"""
5359
Update an existing item.
5460
"""
@@ -63,13 +69,15 @@ async def put(self, item):
6369
}
6470
}
6571
)
66-
return Item.model_validate_json(response)
6772

68-
async def delete(self, vault_id, item_id):
73+
response = TypeAdapter(Item).validate_json(response)
74+
return response
75+
76+
async def delete(self, vault_id: str, item_id: str):
6977
"""
7078
Delete an item.
7179
"""
72-
await _invoke(
80+
response = await _invoke(
7381
{
7482
"invocation": {
7583
"clientId": self.client_id,
@@ -81,7 +89,27 @@ async def delete(self, vault_id, item_id):
8189
}
8290
)
8391

84-
async def list_all(self, vault_id):
92+
return None
93+
94+
async def archive(self, vault_id: str, item_id: str):
95+
"""
96+
Archive an item.
97+
"""
98+
response = await _invoke(
99+
{
100+
"invocation": {
101+
"clientId": self.client_id,
102+
"parameters": {
103+
"name": "ItemsArchive",
104+
"parameters": {"vault_id": vault_id, "item_id": item_id},
105+
},
106+
}
107+
}
108+
)
109+
110+
return None
111+
112+
async def list_all(self, vault_id: str) -> SDKIterator[ItemOverview]:
85113
"""
86114
List all items
87115
"""
@@ -97,8 +125,5 @@ async def list_all(self, vault_id):
97125
}
98126
)
99127

100-
response_data = loads(response)
101-
102-
objects = [ItemOverview.model_validate(data) for data in response_data]
103-
104-
return SDKIterator(objects)
128+
response = TypeAdapter(list[ItemOverview]).validate_json(response)
129+
return SDKIterator(response)

src/onepassword/items_shares.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
from .core import _invoke
4+
from pydantic import TypeAdapter
5+
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient
6+
7+
8+
class ItemsShares:
9+
def __init__(self, client_id):
10+
self.client_id = client_id
11+
12+
async def get_account_policy(
13+
self, vault_id: str, item_id: str
14+
) -> ItemShareAccountPolicy:
15+
"""
16+
Get the item sharing policy of your account.
17+
"""
18+
response = await _invoke(
19+
{
20+
"invocation": {
21+
"clientId": self.client_id,
22+
"parameters": {
23+
"name": "ItemsSharesGetAccountPolicy",
24+
"parameters": {"vault_id": vault_id, "item_id": item_id},
25+
},
26+
}
27+
}
28+
)
29+
30+
response = TypeAdapter(ItemShareAccountPolicy).validate_json(response)
31+
return response
32+
33+
async def validate_recipients(
34+
self, policy: ItemShareAccountPolicy, recipients: list[str]
35+
) -> list[ValidRecipient]:
36+
"""
37+
Validate the recipients of an item sharing link.
38+
"""
39+
response = await _invoke(
40+
{
41+
"invocation": {
42+
"clientId": self.client_id,
43+
"parameters": {
44+
"name": "ItemsSharesValidateRecipients",
45+
"parameters": {
46+
"policy": policy.model_dump(by_alias=True),
47+
"recipients": recipients,
48+
},
49+
},
50+
}
51+
}
52+
)
53+
54+
response = TypeAdapter(list[ValidRecipient]).validate_json(response)
55+
return response
56+
57+
async def create(
58+
self, item: Item, policy: ItemShareAccountPolicy, params: ItemShareParams
59+
) -> str:
60+
"""
61+
Create a new item sharing link.
62+
"""
63+
response = await _invoke(
64+
{
65+
"invocation": {
66+
"clientId": self.client_id,
67+
"parameters": {
68+
"name": "ItemsSharesCreate",
69+
"parameters": {
70+
"item": item.model_dump(by_alias=True),
71+
"policy": policy.model_dump(by_alias=True),
72+
"params": params.model_dump(by_alias=True),
73+
},
74+
},
75+
}
76+
}
77+
)
78+
79+
response = TypeAdapter(str).validate_json(response)
80+
return response
535 KB
Binary file not shown.
602 KB
Binary file not shown.
605 KB
Binary file not shown.

0 commit comments

Comments
 (0)