Skip to content
Closed
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
8 changes: 5 additions & 3 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async def main():
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
Expand Down Expand Up @@ -207,14 +208,15 @@ async def share_item(client: Client, vault_id: str, item_id: str):
item,
policy,
ItemShareParams(
recipients = valid_recipients,
expireAfter= ItemShareDuration.ONEHOUR,
oneTimeOnly= False,
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())
9 changes: 9 additions & 0 deletions src/onepassword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .client import Client
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
from .types import * # noqa F403
from .errors import * # noqa F403
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
Expand All @@ -29,6 +30,14 @@
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
)
or isinstance(obj, int)
or type(obj) == typing._LiteralGenericAlias

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

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

for name, obj in inspect.getmembers(sys.modules["onepassword.errors"]):
# Add all classes defined in errors.py.
if (
inspect.isclass(obj)
and inspect.getmodule(obj) == sys.modules["onepassword.errors"]
):
__all__.append(name)
17 changes: 14 additions & 3 deletions src/onepassword/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import platform

from onepassword.errors import raise_typed_exception


machine_arch = platform.machine().lower()

Expand All @@ -16,17 +18,26 @@

# InitClient creates a client instance in the current core module and returns its unique ID.
async def _init_client(client_config):
return await core.init_client(json.dumps(client_config))
try:
return await core.init_client(json.dumps(client_config))
except Exception as e:
raise_typed_exception(e)


# Invoke calls specified business logic from the SDK core.
async def _invoke(invoke_config):
return await core.invoke(json.dumps(invoke_config))
try:
return await core.invoke(json.dumps(invoke_config))
except Exception as e:
raise_typed_exception(e)


# Invoke calls specified business logic from the SDK core.
def _invoke_sync(invoke_config):
return core.invoke_sync(json.dumps(invoke_config))
try:
return core.invoke_sync(json.dumps(invoke_config))
except Exception as e:
raise_typed_exception(e)


# ReleaseClient releases memory in the SDK core associated with the given client ID.
Expand Down
25 changes: 25 additions & 0 deletions src/onepassword/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

import json


class RateLimitExceededException(Exception):
def __init__(self, message):
self.message = message
super().__init__(self.message)


def raise_typed_exception(e: Exception):
try:
typed_error = json.loads(e.msg)
except Exception:
raise e

message = typed_error.get("message")
error_name = typed_error.get("name")
if error_name == "RateLimitExceeded":
raise RateLimitExceededException(message)
elif message is not None:
raise Exception(message)
else:
raise e
9 changes: 5 additions & 4 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke
from .core import _invoke, _invoke_sync

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items.py:3:28: F401 `.core._invoke_sync` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items.py:3:28: F401 `.core._invoke_sync` imported but unused
from .iterator import SDKIterator
from typing import Optional, List

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items.py:5:20: F401 `typing.Optional` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items.py:5:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .types import Item, ItemCreateParams, ItemOverview
Expand Down Expand Up @@ -73,11 +74,11 @@
response = TypeAdapter(Item).validate_json(response)
return response

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:81:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand All @@ -91,11 +92,11 @@

return None

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:99:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand Down Expand Up @@ -125,5 +126,5 @@
}
)

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

from .core import _invoke
from .core import _invoke, _invoke_sync

Check failure on line 3 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:3:28: F401 `.core._invoke_sync` imported but unused

Check failure on line 3 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:3:28: F401 `.core._invoke_sync` imported but unused
from .iterator import SDKIterator

Check failure on line 4 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:4:23: F401 `.iterator.SDKIterator` imported but unused

Check failure on line 4 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:4:23: F401 `.iterator.SDKIterator` imported but unused
from typing import Optional, List

Check failure on line 5 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:5:20: F401 `typing.Optional` imported but unused

Check failure on line 5 in src/onepassword/items_shares.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_shares.py:5:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient

Expand Down Expand Up @@ -31,8 +33,8 @@
return response

async def validate_recipients(
self, policy: ItemShareAccountPolicy, recipients: list[str]
) -> list[ValidRecipient]:
self, policy: ItemShareAccountPolicy, recipients: List[str]
) -> List[ValidRecipient]:
"""
Validate the recipients of an item sharing link.
"""
Expand All @@ -51,7 +53,7 @@
}
)

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

async def create(
Expand Down
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.
4 changes: 3 additions & 1 deletion src/onepassword/secrets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync
from .iterator import SDKIterator

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/secrets.py:4:23: F401 `.iterator.SDKIterator` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/secrets.py:4:23: F401 `.iterator.SDKIterator` imported but unused
from typing import Optional, List

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/secrets.py:5:20: F401 `typing.Optional` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/secrets.py:5:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import GeneratePasswordResponse, PasswordRecipe

Expand Down Expand Up @@ -34,7 +36,7 @@
return response

@staticmethod
def validate_secret_reference(secret_reference: str):
def validate_secret_reference(secret_reference: str) -> None:
"""
Validate the secret reference to ensure there are no syntax errors.
"""
Expand Down
5 changes: 3 additions & 2 deletions src/onepassword/vaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke
from .core import _invoke, _invoke_sync
from .iterator import SDKIterator
from typing import Optional, List
from pydantic import TypeAdapter
from .types import VaultOverview

Expand All @@ -27,5 +28,5 @@ async def list_all(self) -> SDKIterator[VaultOverview]:
}
)

response = TypeAdapter(list[VaultOverview]).validate_json(response)
response = TypeAdapter(List[VaultOverview]).validate_json(response)
return SDKIterator(response)
Loading