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
29 changes: 18 additions & 11 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ async def main():
# [developer-docs.sdk.python.client-initialization]-end

# [developer-docs.sdk.python.list-vaults]-start
vaults = await client.vaults.list_all()
async for vault in vaults:
vaults = await client.vaults.list()
for vault in vaults:
print(vault.title)
# [developer-docs.sdk.python.list-vaults]-end

# [developer-docs.sdk.python.list-items]-start
items = await client.items.list_all(vault.id)
async for item in items:
print(item.title)
overviews = await client.items.list(vault.id)
for overview in overviews:
print(overview.title)
# [developer-docs.sdk.python.list-items]-end

# [developer-docs.sdk.python.use-item-filters]-start
archived_overviews = await client.items.list(
vault.id,
ItemListFilterByState(
content=ItemListFilterByStateInner(active=False, archived=True)
),
)
for overview in archived_overviews:
print(overview.title)
# [developer-docs.sdk.python.use-item-filters]-end
# [developer-docs.sdk.python.validate-secret-reference]-start
# Validate secret reference to ensure no syntax errors
try:
Expand Down Expand Up @@ -175,24 +184,22 @@ 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)
await share_item(client, updated_item.vault_id, updated_item.id)

await create_ssh_key_item(client, vault_id)

await create_and_replace_document_item(client, vault_id)

await create_attach_and_delete_file_field_item(client, vault_id)

await archive_item(client, updated_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.
Expand Down
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 = "0020101"
SDK_BUILD_NUMBER = "0030001"
16 changes: 9 additions & 7 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

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

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 4 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items.py:4:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .items_files import ItemsFiles
from .types import Item, ItemCreateParams, ItemOverview
from .types import Item, ItemCreateParams, ItemListFilter, ItemOverview


class Items:
Expand Down Expand Up @@ -81,7 +80,7 @@
"""
Delete an item.
"""
response = await _invoke(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:83:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand All @@ -99,7 +98,7 @@
"""
Archive an item.
"""
response = await _invoke(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:101:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand All @@ -113,21 +112,24 @@

return None

async def list_all(self, vault_id: str) -> SDKIterator[ItemOverview]:
async def list(self, vault_id: str, *filters: ItemListFilter) -> List[ItemOverview]:
"""
List all items
List items based on filters.
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsListAll",
"parameters": {"vault_id": vault_id},
"name": "ItemsList",
"parameters": {
"vault_id": vault_id,
"filters": [o.model_dump(by_alias=True) for o in filters],
},
},
}
}
)

response = TypeAdapter(List[ItemOverview]).validate_json(response)
return SDKIterator(response)
return response
1 change: 0 additions & 1 deletion src/onepassword/items_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

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

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_files.py:4:20: F401 `typing.Optional` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_files.py:4:20: F401 `typing.Optional` imported but unused

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F401)

src/onepassword/items_files.py:4:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import DocumentCreateParams, FileAttributes, FileCreateParams, Item
Expand Down
1 change: 0 additions & 1 deletion src/onepassword/items_shares.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

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

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
from typing import Optional, List

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:20: F401 `typing.Optional` 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:20: F401 `typing.Optional` 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:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient
Expand Down
25 changes: 0 additions & 25 deletions src/onepassword/iterator.py

This file was deleted.

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

from .core import _invoke, _invoke_sync
from .iterator import SDKIterator
from typing import Optional, List

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:20: F401 `typing.Optional` 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:20: F401 `typing.Optional` 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:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import GeneratePasswordResponse, PasswordRecipe, ResolveAllResponse

Expand Down
42 changes: 41 additions & 1 deletion src/onepassword/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class ItemFile(BaseModel):

class Item(BaseModel):
"""
Represents a 1Password item.
Represents an active 1Password item.
"""

model_config = ConfigDict(populate_by_name=True)
Expand Down Expand Up @@ -448,6 +448,21 @@ class ItemCreateParams(BaseModel):
"""


class ItemState(str, Enum):
"""
Represents the state of an item in the SDK.
"""

ACTIVE = "active"
"""
The item is active
"""
ARCHIVED = "archived"
"""
The item is archived meaning it's hidden from regular view and stored in the archive.
"""


class ItemOverview(BaseModel):
"""
Represents a decrypted 1Password item overview.
Expand Down Expand Up @@ -495,6 +510,10 @@ class ItemOverview(BaseModel):
"""
The time the item was updated at
"""
state: ItemState
"""
Indicates the state of the item
"""


class ItemShareDuration(str, Enum):
Expand Down Expand Up @@ -967,6 +986,27 @@ class VaultOverview(BaseModel):
"""


class ItemListFilterByStateInner(BaseModel):
"""
Generated type representing the anonymous struct variant `ByState` of the `ItemListFilter` Rust enum
"""

active: bool
archived: bool


class ItemListFilterTypes(str, Enum):
BY_STATE = "ByState"


class ItemListFilterByState(BaseModel):
type: Literal[ItemListFilterTypes.BY_STATE] = ItemListFilterTypes.BY_STATE
content: ItemListFilterByStateInner


ItemListFilter = ItemListFilterByState


class PasswordRecipeMemorableInner(BaseModel):
"""
Generated type representing the anonymous struct variant `Memorable` of the `PasswordRecipe` Rust enum
Expand Down
7 changes: 3 additions & 4 deletions src/onepassword/vaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

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 @@ -15,18 +14,18 @@ class Vaults:
def __init__(self, client_id):
self.client_id = client_id

async def list_all(self) -> SDKIterator[VaultOverview]:
async def list(self) -> List[VaultOverview]:
"""
List all vaults
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {"name": "VaultsListAll", "parameters": {}},
"parameters": {"name": "VaultsList", "parameters": {}},
}
}
)

response = TypeAdapter(List[VaultOverview]).validate_json(response)
return SDKIterator(response)
return response
72 changes: 59 additions & 13 deletions src/release/RELEASE-NOTES
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
# 1Password Python SDK v0.2.1
# 1Password Python SDK v0.3.0

## NEW

- **`CreatedAt` and `UpdatedAt` item metadata:** Items and item overviews now expose attributes with their creation and last edit times.
- **Resolving secrets in bulk**: With the `client.secrets.resolveAll` function, the SDK is now able to resolve multiple secrets at once, improving the performance of the operation.
- **Support for item states**: You can now fetch an item's state using the SDK. `ItemOverview` exposes one of two states: `Active` or `Archived`.
- `Active`: An item located inside a vault. (Default)
- `Archived`: An item that has been moved to the Archive. 1Password doesn't include archived items in search results or suggest them when you fill in apps and browsers. You can keep archived items as long as you'd like.
- **Filtering listed items by state**: You can now filter the results of the item list function by item state.

## IMPROVED
## FIXED

- **Support for new field types:** Items with `Address` and `Date` fields can now be created, retrieved, and edited using the 1Password SDK.
- **Item sharing for attachments and documents**: Items with files attached now can also be shared using the `client.items.shares` functions.
- **Adding custom fields in sections automatically**: The SDK now automatically adds custom fields without a section to an empty section within the item, creating it if necessary.
- **`Tags` in item overviews**: The return type of `items.listAll` now also contains the item tags.
- **Broader item editing capabilities**: You are now able to use the `items.put` function on more items, including those with fields that are not directly editable through the SDK (such as legacy fields, passkeys etc.)
- **Deleting Archived Items:** The SDK now supports deleting items from the archive.

## FIXED
## ⚠️ BREAKING CHANGES ⚠️
This release contains breaking changes for two functions in the Python SDK.

**Vault listing**

* The function name has changed from `list_all` to `list`. To use this in your code, replace:
```python
vaults = await client.vaults.list_all(vault_id)
```
with:
```python
vaults = await client.vaults.list(vault_id)
```

* The return type of the vault listing function has changed from `SDKIterator[VaultOverview]` to `List[VaultOverview]`. To use this in your code, replace:

```python
async for vault in vaults:
# using vault overview
```
with:
```python
for vault in vaults:
# using vault overview
```
**Item listing**

* The function name has changed from `ListAll` to `List`. To use this in your code, replace:
```python
overviews = await client.items.list_all(vault_id)
```
with:
```python
overviews = await client.items.list(vault_id, ItemListFilter(
content=ItemListFilterByStateInner(
active=True,
archived=True,
)
))
```

* The return type of the item listing function has changed from `SDKIterator[ItemOverview]` to `List[ItemOverview]`. To use this in your code, replace:
```python
async for overview in overviews:
# using item overview
```
with:
```python
for overview in overviews:
# using item overview
```

- **Improvements to resolving secret references:**
- Archived items are no longer used for secret references.
- When multiple sections match a section query in resolving secret references, the SDK look through the fields in all sections, instead of erroring.
This does not affect any code that's already deployed, and will not take effect in your codebase until you choose to update to version 0.3.0 or later of the 1Password Python SDK.
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SDK_VERSION = "0.2.1"
SDK_VERSION = "0.3.0"
Loading