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
4 changes: 2 additions & 2 deletions example/desktop_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main():
# Connects to the 1Password desktop app.
client = await Client.authenticate(
auth=DesktopAuth(
account_name="YourAccountNameAsItAppearsInTheApp" # Set to your 1Password account name.
account_name="YouAccountNameAsShownInDesktopApp" # Set to your 1Password account name.
),
# Set the following to your own integration name and version.
integration_name="My 1Password Integration",
Expand All @@ -22,7 +22,7 @@ async def main():
# [developer-docs.sdk.python.list-vaults]-end

# [developer-docs.sdk.python.list-items]-start
overviews = await client.items.list(vault.id)
overviews = await client.items.list(vault_id=vaults[0].id)
for overview in overviews:
print(overview.title)
# [developer-docs.sdk.python.list-items]-end
Expand Down
2 changes: 2 additions & 0 deletions src/onepassword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
from .groups import Groups


import sys
Expand All @@ -18,6 +19,7 @@
"Secrets",
"Items",
"Vaults",
"Groups",
"DEFAULT_INTEGRATION_NAME",
"DEFAULT_INTEGRATION_VERSION",
"DesktopAuth",
Expand All @@ -31,7 +33,7 @@
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
)
or isinstance(obj, int)
or type(obj) == typing._LiteralGenericAlias

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

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

Expand Down
6 changes: 5 additions & 1 deletion src/onepassword/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

from __future__ import annotations
import weakref
from .core import Core, UniffiCore
from .core import UniffiCore
from .desktop_core import DesktopCore
from .defaults import new_default_config, DesktopAuth
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
from .groups import Groups


class Client:
secrets: Secrets
items: Items
vaults: Vaults
groups: Groups

@classmethod
async def authenticate(
Expand All @@ -37,6 +39,8 @@ async def authenticate(
authenticated_client.secrets = Secrets(client_id, core)
authenticated_client.items = Items(client_id, core)
authenticated_client.vaults = Vaults(client_id, core)
authenticated_client.groups = Groups(client_id, core)

authenticated_client._finalizer = weakref.finalize(
cls, core.release_client, client_id
)
Expand Down
2 changes: 1 addition & 1 deletion src/onepassword/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def new_default_config(auth: DesktopAuth | str, integration_name, integration_ve
"osVersion": DEFAULT_OS_VERSION,
"architecture": platform.machine(),
}
if isinstance(auth, str):
if not isinstance(auth, DesktopAuth):
client_config_dict["serviceAccountToken"] = auth

return client_config_dict
1 change: 0 additions & 1 deletion src/onepassword/desktop_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import platform
import base64
from pathlib import Path
from ctypes import c_uint8, c_size_t, c_int32, POINTER, byref, c_void_p

Check failure on line 7 in src/onepassword/desktop_core.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/desktop_core.py:7:64: F401 `ctypes.c_void_p` imported but unused

Check failure on line 7 in src/onepassword/desktop_core.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/desktop_core.py:7:64: F401 `ctypes.c_void_p` imported but unused
from .core import UniffiCore
from onepassword.errors import raise_typed_exception


Expand Down
34 changes: 34 additions & 0 deletions src/onepassword/groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import Core
from pydantic import TypeAdapter
from .types import Group, GroupGetParams


class Groups:
"""
The Groups API holds all the operations the SDK client can perform on 1Password groups.
"""

def __init__(self, client_id, core: Core):
self.client_id = client_id
self.core = core

async def get(self, group_id: str, group_params: GroupGetParams) -> Group:
response = await self.core.invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "GroupsGet",
"parameters": {
"group_id": group_id,
"group_params": group_params.model_dump(by_alias=True),
},
},
}
}
)

response = TypeAdapter(Group).validate_json(response)
return response
79 changes: 76 additions & 3 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from typing import Optional, List
from .core import Core
from typing import List
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .items_files import ItemsFiles
from .types import Item, ItemCreateParams, ItemListFilter, ItemOverview
from .types import (
Item,
ItemCreateParams,
ItemListFilter,
ItemOverview,
ItemsDeleteAllResponse,
ItemsGetAllResponse,
ItemsUpdateAllResponse,
)


class Items:
"""
The Items API holds all operations the SDK client can perform on 1Password items.
"""

def __init__(self, client_id, core):
def __init__(self, client_id, core: Core):
self.client_id = client_id
self.core = core
self.shares = ItemsShares(client_id, core)
Expand All @@ -37,6 +46,30 @@
response = TypeAdapter(Item).validate_json(response)
return response

async def create_all(
self, vault_id: str, params: List[ItemCreateParams]
) -> ItemsUpdateAllResponse:
"""
Create items in batch, within a single vault.
"""
response = await self.core.invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsCreateAll",
"parameters": {
"vault_id": vault_id,
"params": [o.model_dump(by_alias=True) for o in params],
},
},
}
}
)

response = TypeAdapter(ItemsUpdateAllResponse).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 @@ -56,6 +89,25 @@
response = TypeAdapter(Item).validate_json(response)
return response

async def get_all(self, vault_id: str, item_ids: List[str]) -> ItemsGetAllResponse:
"""
Get items by vault and their item IDs.
"""
response = await self.core.invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsGetAll",
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
},
}
}
)

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

async def put(self, item: Item) -> Item:
"""
Update an existing item.
Expand All @@ -79,7 +131,7 @@
"""
Delete an item.
"""
response = await self.core.invoke(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

return None

async def delete_all(
self, vault_id: str, item_ids: List[str]
) -> ItemsDeleteAllResponse:
"""
Create items in batch, within a single vault.
"""
response = await self.core.invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsDeleteAll",
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
},
}
}
)

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

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:173:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand Down
4 changes: 2 additions & 2 deletions src/onepassword/items_files.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import Core
from typing import Optional, List
from typing import List
from pydantic import TypeAdapter
from .types import DocumentCreateParams, FileAttributes, FileCreateParams, Item


class ItemsFiles:
def __init__(self, client_id, core):
def __init__(self, client_id, core: Core):
self.client_id = client_id
self.core = core

Expand Down
2 changes: 1 addition & 1 deletion src/onepassword/items_shares.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from typing import Optional, List
from typing import List
from pydantic import TypeAdapter
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient

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.
10 changes: 5 additions & 5 deletions src/onepassword/secrets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import Core
from typing import Optional, List
from .core import Core, UniffiCore
from typing import List
from pydantic import TypeAdapter
from .types import GeneratePasswordResponse, PasswordRecipe, ResolveAllResponse

Expand All @@ -12,7 +12,7 @@
Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>
"""

def __init__(self, client_id, core):
def __init__(self, client_id, core: Core):
self.client_id = client_id
self.core = core

Expand Down Expand Up @@ -59,7 +59,7 @@
"""
Validate the secret reference to ensure there are no syntax errors.
"""
response = self.core.invoke_sync(
response = UniffiCore().invoke_sync(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/secrets.py:62:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"parameters": {
Expand All @@ -74,7 +74,7 @@

@staticmethod
def generate_password(recipe: PasswordRecipe) -> GeneratePasswordResponse:
response = self.core.invoke_sync(
response = UniffiCore().invoke_sync(
{
"invocation": {
"parameters": {
Expand Down
Loading
Loading