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
36 changes: 25 additions & 11 deletions example/desktop_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ async def main():
# Connect to the 1Password desktop app
client = await Client.authenticate(
auth=DesktopAuth(
account_name="YourAccountNameAsShownInTheDesktopApp" # Set to your 1Password account name as shown at the top left sidebar of the app, or your account UUID.
# Set to your 1Password account name as shown at the top left sidebar of the app, or your account UUID.
account_name="YourAccountNameAsShownInTheDesktopApp"
),
# Set to your own integration name and version
integration_name="My 1Password Integration",
Expand Down Expand Up @@ -42,16 +43,26 @@ async def main():
group_id = os.environ.get("OP_GROUP_ID")
if group_id is None:
raise Exception("OP_GROUP_ID is required")

await showcase_group_permission_operations(client, vault_id, group_id)

environment_id = os.environ.get("OP_ENVIRONMENT_ID")
if environment_id is not None:
# [developer-docs.sdk.python.get-environment-variables]-start
# Read variables from a 1Password Environment
environment = await client.environments.get_variables(environment_id)
for variable in environment.variables:
print(f"{variable.name}: {variable.value} (masked: {variable.masked})")
# [developer-docs.sdk.python.get-environment-variables]-end


async def showcase_vault_operations(client: Client):
# [developer-docs.sdk.python.create-vault]-start
# Create a vault
vault_create_params = VaultCreateParams(
title="Python SDK Vault",
description="A description",
allow_admins_access=False,
title="Python SDK Vault",
description="A description",
allow_admins_access=False,
)
created_vault = await client.vaults.create(vault_create_params)
print(f"Created vault: {created_vault.id} - {created_vault.title}")
Expand All @@ -69,7 +80,7 @@ async def showcase_vault_operations(client: Client):
title="Python SDK Updated Name",
description="Updated description",
)

await client.vaults.update(created_vault.id, update_params)
# [developer-docs.sdk.python.update-vault]-end

Expand All @@ -95,6 +106,7 @@ async def showcase_vault_operations(client: Client):
print(vault.title)
# [developer-docs.sdk.python.list-vault]-end


async def showcase_group_permission_operations(client: Client, vault_id: str, group_id: str):
# [developer-docs.sdk.python.grant-group-permissions]-start
# Grant group permissions in a vault
Expand All @@ -117,7 +129,7 @@ async def showcase_group_permission_operations(client: Client, vault_id: str, gr
GroupVaultAccess(
vault_id=vault_id,
group_id=group_id,
permissions= READ_ITEMS | CREATE_ITEMS | UPDATE_ITEMS,
permissions=READ_ITEMS | CREATE_ITEMS | UPDATE_ITEMS,
)
],
)
Expand All @@ -131,13 +143,14 @@ async def showcase_group_permission_operations(client: Client, vault_id: str, gr
group_id=group_id,
)
# [developer-docs.sdk.python.update-group-permissions]-end

# [developer-docs.sdk.python.get-group]-start
# Get a group
group = await client.groups.get(group_id, GroupGetParams(vaultPermissions=False))
print(group)
# [developer-docs.sdk.python.get-group]-end


async def showcase_batch_item_operations(client: Client, vault_id: str):
# [developer-docs.sdk.python.batch-create-items]-start
items_to_create = []
Expand Down Expand Up @@ -189,7 +202,8 @@ async def showcase_batch_item_operations(client: Client, vault_id: str):
item_ids = []
for res in batchCreateResponse.individual_responses:
if res.content is not None:
print('Created item "{}" ({})'.format(res.content.title, res.content.id))
print('Created item "{}" ({})'.format(
res.content.title, res.content.id))
item_ids.append(res.content.id)
elif res.error is not None:
print("[Batch create] Something went wrong: {}".format(res.error))
Expand All @@ -200,7 +214,8 @@ async def showcase_batch_item_operations(client: Client, vault_id: str):
batchGetReponse = await client.items.get_all(vault_id, item_ids)
for res in batchGetReponse.individual_responses:
if res.content is not None:
print('Obtained item "{}" ({})'.format(res.content.title, res.content.id))
print('Obtained item "{}" ({})'.format(
res.content.title, res.content.id))
elif res.error is not None:
print("[Batch get] Something went wrong: {}".format(res.error))
# [developer-docs.sdk.python.batch-get-items]-end
Expand All @@ -215,6 +230,5 @@ async def showcase_batch_item_operations(client: Client, vault_id: str):
print("Deleted item {}".format(id))
# [developer-docs.sdk.python.batch-delete-items]-end


if __name__ == "__main__":
asyncio.run(main())
25 changes: 19 additions & 6 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,23 @@ async def main():

await showcase_batch_item_operations(client, vault_id)

environment_id = os.environ.get("OP_ENVIRONMENT_ID")
if environment_id is not None:
# [developer-docs.sdk.python.get-environment-variables]-start
# Read variables from a 1Password Environment
environment = await client.environments.get_variables(environment_id)
for variable in environment.variables:
print(f"{variable.name}: {variable.value} (masked: {variable.masked})")
# [developer-docs.sdk.python.get-environment-variables]-end


async def showcase_vault_operations(client: Client):
# [developer-docs.sdk.python.create-vault]-start
# Create a vault
vault_create_params = VaultCreateParams(
title="Python SDK Vault",
description="A description",
allow_admins_access=False,
title="Python SDK Vault",
description="A description",
allow_admins_access=False,
)
created_vault = await client.vaults.create(vault_create_params)
print(f"Created vault: {created_vault.id} - {created_vault.title}")
Expand Down Expand Up @@ -259,6 +269,7 @@ async def showcase_vault_operations(client: Client):
print(f"{vault.title} ({vault.id})")
# [developer-docs.sdk.python.list-vault]-end


async def showcase_batch_item_operations(client: Client, vault_id: str):
# [developer-docs.sdk.python.batch-create-items]-start
items_to_create = []
Expand Down Expand Up @@ -310,7 +321,8 @@ async def showcase_batch_item_operations(client: Client, vault_id: str):
item_ids = []
for res in batchCreateResponse.individual_responses:
if res.content is not None:
print('Created item "{}" ({})'.format(res.content.title, res.content.id))
print('Created item "{}" ({})'.format(
res.content.title, res.content.id))
item_ids.append(res.content.id)
elif res.error is not None:
print("[Batch create] Something went wrong: {}".format(res.error))
Expand All @@ -321,7 +333,8 @@ async def showcase_batch_item_operations(client: Client, vault_id: str):
batchGetReponse = await client.items.get_all(vault_id, item_ids)
for res in batchGetReponse.individual_responses:
if res.content is not None:
print('Obtained item "{}" ({})'.format(res.content.title, res.content.id))
print('Obtained item "{}" ({})'.format(
res.content.title, res.content.id))
elif res.error is not None:
print("[Batch get] Something went wrong: {}".format(res.error))
# [developer-docs.sdk.python.batch-get-items]-end
Expand Down Expand Up @@ -657,7 +670,7 @@ async def showcase_group_permission_operations(client: Client, vault_id: str, gr
)
print(f"Revoked group {group_id}'s permissions in vault {vault_id}")
# [developer-docs.sdk.python.revoke-group-permissions]-end

# [developer-docs.sdk.python.get-group]-start
# Get a group
group = await client.groups.get(group_id, GroupGetParams(vaultPermissions=False))
Expand Down
2 changes: 2 additions & 0 deletions src/onepassword/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .client import Client, DesktopAuth
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
from .types import * # noqa F403

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF100)

src/onepassword/__init__.py:5:23: RUF100 Unused blanket `noqa` directive help: Remove unused `noqa` directive

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF100)

src/onepassword/__init__.py:5:23: RUF100 Unused blanket `noqa` directive help: Remove unused `noqa` directive
from .errors import * # noqa F403

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF100)

src/onepassword/__init__.py:6:24: RUF100 Unused blanket `noqa` directive help: Remove unused `noqa` directive

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF100)

src/onepassword/__init__.py:6:24: RUF100 Unused blanket `noqa` directive help: Remove unused `noqa` directive
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
from .environments import Environments
from .groups import Groups


Expand All @@ -14,16 +15,17 @@
import inspect
import typing

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (I001)

src/onepassword/__init__.py:3:1: I001 Import block is un-sorted or un-formatted help: Organize imports

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (I001)

src/onepassword/__init__.py:3:1: I001 Import block is un-sorted or un-formatted help: Organize imports

__all__ = [
"Client",
"Secrets",
"Items",
"Vaults",
"Environments",
"Groups",
"DesktopAuth",
"DEFAULT_INTEGRATION_NAME",
"DEFAULT_INTEGRATION_VERSION",
]

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF022)

src/onepassword/__init__.py:18:11: RUF022 `__all__` is not sorted help: Apply an isort-style sorting to `__all__`

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

View workflow job for this annotation

GitHub Actions / Lint

ruff (RUF022)

src/onepassword/__init__.py:18:11: RUF022 `__all__` is not sorted help: Apply an isort-style sorting to `__all__`

for name, obj in inspect.getmembers(sys.modules["onepassword.types"]):
# Add all classes and instances of typing.Literal defined in types.py.
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 = "0040003"
SDK_BUILD_NUMBER = "0040101"
3 changes: 3 additions & 0 deletions src/onepassword/client.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from __future__ import annotations
import weakref
from .core import UniffiCore, InnerClient
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 .environments import Environments
from .groups import Groups

Check failure on line 12 in src/onepassword/client.py

View workflow job for this annotation

GitHub Actions / Lint

ruff (I001)

src/onepassword/client.py:3:1: I001 Import block is un-sorted or un-formatted help: Organize imports

Check failure on line 12 in src/onepassword/client.py

View workflow job for this annotation

GitHub Actions / Lint

ruff (I001)

src/onepassword/client.py:3:1: I001 Import block is un-sorted or un-formatted help: Organize imports


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

@classmethod
Expand All @@ -41,6 +43,7 @@
authenticated_client.secrets = Secrets(inner_client)
authenticated_client.items = Items(inner_client)
authenticated_client.vaults = Vaults(inner_client)
authenticated_client.environments = Environments(inner_client)
authenticated_client.groups = Groups(inner_client)
authenticated_client._finalizer = weakref.finalize(
cls, core.release_client, client_id
Expand Down
33 changes: 33 additions & 0 deletions src/onepassword/environments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import InnerClient
from pydantic import TypeAdapter
from .types import GetVariablesResponse


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

def __init__(self, inner_client: InnerClient):
self.inner_client = inner_client

async def get_variables(self, environment_id: str) -> GetVariablesResponse:
"""
Get environment variables belonging to an Environment.
"""
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.inner_client.client_id,
"parameters": {
"name": "EnvironmentsGetVariables",
"parameters": {"environment_id": environment_id},
},
}
}
)

response = TypeAdapter(GetVariablesResponse).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.
30 changes: 30 additions & 0 deletions src/onepassword/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ class DocumentCreateParams(BaseModel):
"""


class EnvironmentVariable(BaseModel):
"""
Represents an environment variable (name:value pair) and its masked state
"""

name: str
"""
An environment variable's name
"""
value: str
"""
An environment variable's value
"""
masked: bool
"""
An environment variable's masked state
"""


class FileAttributes(BaseModel):
name: str
"""
Expand Down Expand Up @@ -140,6 +159,17 @@ class GeneratePasswordResponse(BaseModel):
"""


class GetVariablesResponse(BaseModel):
"""
Response containing the full set of environment variables from an Environment.
"""

variables: List[EnvironmentVariable]
"""
List of environment variables.
"""


class GroupType(str, Enum):
OWNERS = "owners"
"""
Expand Down
7 changes: 2 additions & 5 deletions src/release/RELEASE-NOTES
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# 1Password Python SDK v0.4.0
# 1Password Python SDK v0.4.1b1

## NEW

- **Desktop App integration:** The SDK can now authenticate via an authorization prompt from the 1Password app.
- **Vault CRUDL:** You can now fully manage 1Password vaults with the SDK, including creating, reading, updating, deleting and listing.
- **Vault group permission management operations:** You can now grant, update and revoke group access to vaults using `grantGroupPermissions`, `updateGroupPermissions`, and `revokeGroupPermissions` functions.
- **Item batch management:** You can now retrieve, create, update and delete items in batch, enabling more scalable item management.

- **1Password Environment access:** The SDK can now read variables from a 1Password Environment.
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SDK_VERSION = "0.4.0"
SDK_VERSION = "0.4.1b1"
Loading