Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,28 @@ Operations:
- [x] [Create items](https://developer.1password.com/docs/sdks/manage-items#create-an-item)
- [x] [Update items](https://developer.1password.com/docs/sdks/manage-items#update-an-item)
- [x] [Delete items](https://developer.1password.com/docs/sdks/manage-items#delete-an-item)
- [x] Archive items
- [x] [List items](https://developer.1password.com/docs/sdks/list-vaults-items/)
- [x] Add & update tags on items
- [x] Share items
- [x] Generate PIN, random and memorable passwords

Field types:
- [x] API Keys
- [x] Passwords
- [x] Concealed fields
- [x] Text fields
- [ ] Notes
- [x] SSH private keys (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
- [ ] SSH public keys, fingerprint and key type
- [x] Notes
- [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)
- [x] One-time passwords
- [x] URLs
- [x] Websites (used to suggest and autofill logins)
- [x] Phone numbers
- [x] Credit card types
- [x] Credit card numbers
- [x] Emails
- [x] References to other items
- [ ] Address
- [ ] Date / MM/YY
- [ ] Files attachments and Document items

### Vault management
Expand Down
45 changes: 45 additions & 0 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,56 @@ async def main():
print(random_password)
# [developer-docs.sdk.python.generate-random-password]-end

await share_item(client, created_item.vault_id, updated_item.id)

# [developer-docs.sdk.python.delete-item]-start
# Delete a item from your vault.
await client.items.delete(created_item.vault_id, updated_item.id)
# [developer-docs.sdk.python.delete-item]-end

## NOTE: this is in a separate function to avoid creating a new item
## NOTE: just for the sake of archiving it. This is because the SDK
## NOTE: only works with active items, so archiving and then deleting
## NOTE: is not yet possible.
async def archive_item(client: Client, vault_id: str, item_id: str):
# [developer-docs.sdk.python.archive-item]-start
# Archive a item from your vault.
await client.items.archive(vault_id, item_id)
# [developer-docs.sdk.python.archive-item]-end


async def share_item(client: Client, vault_id: str, item_id: str):
# [developer-docs.sdk.python.item-share-get-item]-start
item = await client.items.get(vault_id, item_id)
print(item)
# [developer-docs.sdk.python.item-share-get-item]-end

# [developer-docs.sdk.python.item-share-get-account-policy]-start
policy = await client.items.shares.get_account_policy(item.vault_id, item.id)
print(policy)
# [developer-docs.sdk.python.item-share-get-account-policy]-end

# [developer-docs.sdk.python.item-share-validate-recipients]-start
valid_recipients = await client.items.shares.validate_recipients(
policy, ["agilebits.com"]
)

print(valid_recipients)
# [developer-docs.sdk.python.item-share-validate-recipients]-end

# [developer-docs.sdk.python.item-share-create-share]-start
share_link = await client.items.shares.create(
item,
policy,
ItemShareParams(
recipients = valid_recipients,
expireAfter= ItemShareDuration.ONEHOUR,
oneTimeOnly= False,
),
)

print(share_link)
# [developer-docs.sdk.python.item-share-create-share]-end

if __name__ == "__main__":
asyncio.run(main())
10 changes: 7 additions & 3 deletions src/onepassword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
for name, obj in inspect.getmembers(sys.modules["onepassword.types"]):
# Add all classes and instances of typing.Literal defined in types.py.
if (
inspect.isclass(obj)
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
) or type(eval(name)) == typing._LiteralGenericAlias:
(
inspect.isclass(obj)
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
)
or isinstance(obj, int)
or type(obj) == typing._LiteralGenericAlias

Check failure on line 32 in src/onepassword/__init__.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

src/onepassword/__init__.py:32:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

Check failure on line 32 in src/onepassword/__init__.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

src/onepassword/__init__.py:32:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

Check failure on line 32 in src/onepassword/__init__.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

src/onepassword/__init__.py:32:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
):
__all__.append(name)
2 changes: 1 addition & 1 deletion src/onepassword/build_number.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SDK_BUILD_NUMBER = "0010501"
SDK_BUILD_NUMBER = "0010601"
5 changes: 4 additions & 1 deletion src/onepassword/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from __future__ import annotations
import weakref
from .core import _init_client, _release_client
from .defaults import new_default_config
Expand All @@ -14,7 +15,9 @@ class Client:
vaults: Vaults

@classmethod
async def authenticate(cls, auth, integration_name, integration_version):
async def authenticate(
cls, auth: str, integration_name: str, integration_version: str
) -> Client:
config = new_default_config(
auth=auth or "",
integration_name=integration_name,
Expand Down
61 changes: 43 additions & 18 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync
from json import loads
from .core import _invoke
from .iterator import SDKIterator
from .types import Item, ItemOverview
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .types import Item, ItemCreateParams, ItemOverview


class Items:
Expand All @@ -13,10 +14,11 @@

def __init__(self, client_id):
self.client_id = client_id
self.shares = ItemsShares(client_id)

async def create(self, params):
async def create(self, params: ItemCreateParams) -> Item:
"""
Create a new item
Create a new item.
"""
response = await _invoke(
{
Expand All @@ -29,9 +31,11 @@
}
}
)
return Item.model_validate_json(response)

async def get(self, vault_id, item_id):
response = TypeAdapter(Item).validate_json(response)
return response

async def get(self, vault_id: str, item_id: str) -> Item:
"""
Get an item by vault and item ID
"""
Expand All @@ -46,9 +50,11 @@
}
}
)
return Item.model_validate_json(response)

async def put(self, item):
response = TypeAdapter(Item).validate_json(response)
return response

async def put(self, item: Item) -> Item:
"""
Update an existing item.
"""
Expand All @@ -63,13 +69,15 @@
}
}
)
return Item.model_validate_json(response)

async def delete(self, vault_id, item_id):
response = TypeAdapter(Item).validate_json(response)
return response

async def delete(self, vault_id: str, item_id: str):
"""
Delete an item.
"""
await _invoke(
response = await _invoke(

Check failure on line 80 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:80:9: F841 Local variable `response` is assigned to but never used

Check failure on line 80 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:80:9: F841 Local variable `response` is assigned to but never used

Check failure on line 80 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:80:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand All @@ -81,7 +89,27 @@
}
)

async def list_all(self, vault_id):
return None

async def archive(self, vault_id: str, item_id: str):
"""
Archive an item.
"""
response = await _invoke(

Check failure on line 98 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:98:9: F841 Local variable `response` is assigned to but never used

Check failure on line 98 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:98:9: F841 Local variable `response` is assigned to but never used

Check failure on line 98 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:98:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsArchive",
"parameters": {"vault_id": vault_id, "item_id": item_id},
},
}
}
)

return None

async def list_all(self, vault_id: str) -> SDKIterator[ItemOverview]:
"""
List all items
"""
Expand All @@ -97,8 +125,5 @@
}
)

response_data = loads(response)

objects = [ItemOverview.model_validate(data) for data in response_data]

return SDKIterator(objects)
response = TypeAdapter(list[ItemOverview]).validate_json(response)
return SDKIterator(response)
80 changes: 80 additions & 0 deletions src/onepassword/items_shares.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke
from pydantic import TypeAdapter
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient


class ItemsShares:
def __init__(self, client_id):
self.client_id = client_id

async def get_account_policy(
self, vault_id: str, item_id: str
) -> ItemShareAccountPolicy:
"""
Get the item sharing policy of your account.
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsSharesGetAccountPolicy",
"parameters": {"vault_id": vault_id, "item_id": item_id},
},
}
}
)

response = TypeAdapter(ItemShareAccountPolicy).validate_json(response)
return response

async def validate_recipients(
self, policy: ItemShareAccountPolicy, recipients: list[str]
) -> list[ValidRecipient]:
"""
Validate the recipients of an item sharing link.
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsSharesValidateRecipients",
"parameters": {
"policy": policy.model_dump(by_alias=True),
"recipients": recipients,
},
},
}
}
)

response = TypeAdapter(list[ValidRecipient]).validate_json(response)
return response

async def create(
self, item: Item, policy: ItemShareAccountPolicy, params: ItemShareParams
) -> str:
"""
Create a new item sharing link.
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsSharesCreate",
"parameters": {
"item": item.model_dump(by_alias=True),
"policy": policy.model_dump(by_alias=True),
"params": params.model_dump(by_alias=True),
},
},
}
}
)

response = TypeAdapter(str).validate_json(response)
return response
Binary file modified src/onepassword/lib/aarch64/libop_uniffi_core.dylib
Binary file not shown.
Binary file modified src/onepassword/lib/aarch64/libop_uniffi_core.so
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/libop_uniffi_core.dylib
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/libop_uniffi_core.so
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/op_uniffi_core.dll
Binary file not shown.
23 changes: 14 additions & 9 deletions src/onepassword/secrets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync
from json import loads
from .iterator import SDKIterator
from .types import GeneratePasswordResponse
from pydantic import TypeAdapter
from .types import GeneratePasswordResponse, PasswordRecipe


class Secrets:
Expand All @@ -15,7 +14,7 @@
def __init__(self, client_id):
self.client_id = client_id

async def resolve(self, secret_reference):
async def resolve(self, secret_reference: str) -> str:
"""
Resolve returns the secret the provided secret reference points to.
"""
Expand All @@ -30,14 +29,16 @@
}
}
)
return str(loads(response))

response = TypeAdapter(str).validate_json(response)
return response

@staticmethod
def validate_secret_reference(secret_reference):
def validate_secret_reference(secret_reference: str):
"""
Validate the secret reference to ensure there are no syntax errors.
"""
_invoke_sync(
response = _invoke_sync(

Check failure on line 41 in src/onepassword/secrets.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/secrets.py:41:9: F841 Local variable `response` is assigned to but never used

Check failure on line 41 in src/onepassword/secrets.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/secrets.py:41:9: F841 Local variable `response` is assigned to but never used

Check failure on line 41 in src/onepassword/secrets.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/secrets.py:41:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"parameters": {
Expand All @@ -48,8 +49,10 @@
}
)

return None

@staticmethod
def generate_password(recipe):
def generate_password(recipe: PasswordRecipe) -> GeneratePasswordResponse:
response = _invoke_sync(
{
"invocation": {
Expand All @@ -60,4 +63,6 @@
}
}
)
return GeneratePasswordResponse.model_validate_json(response)

response = TypeAdapter(GeneratePasswordResponse).validate_json(response)
return response
Loading
Loading