1Password Connect Python SDK

2.0.0 · active · verified Thu Apr 16

The 1Password Connect Python SDK provides a convenient way to interact with the 1Password Connect API, allowing applications to retrieve and manage secrets stored in 1Password vaults. The current version is 2.0.0, released in July 2024, with a fairly active development cadence addressing features, fixes, and dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Initialize the 1Password Connect client and fetch items from a specified vault. This example relies on environment variables for configuration. Make sure `OP_CONNECT_HOST`, `OP_CONNECT_TOKEN`, and `OP_VAULT_UUID` are set.

import os
from onepasswordconnectsdk import client

# Configure 1Password Connect client via environment variables:
# OP_CONNECT_HOST - e.g., "http://localhost:8080"
# OP_CONNECT_TOKEN - your 1Password Connect server token
# OP_VAULT_UUID - the UUID of a vault you want to access

host = os.environ.get("OP_CONNECT_HOST", "http://localhost:8080")
token = os.environ.get("OP_CONNECT_TOKEN", "dummy_token_replace_me")
vault_uuid = os.environ.get("OP_VAULT_UUID", "dummy_vault_uuid_replace_me")

if token == "dummy_token_replace_me" or vault_uuid == "dummy_vault_uuid_replace_me":
    print("Please set OP_CONNECT_HOST, OP_CONNECT_TOKEN, and OP_VAULT_UUID environment variables.")
    print("For this quickstart, we'll proceed but it will likely fail without real credentials.")

try:
    connect_client = client.Client(host, token)
    print(f"Connecting to 1Password Connect server at: {host}")
    items = connect_client.get_items(vault_uuid)
    print(f"Successfully retrieved {len(items)} items from vault {vault_uuid}.")
    for item in items[:3]: # Print first 3 item titles
        print(f"- {item.title}")
except Exception as e:
    print(f"Error: {e}")
    print("Ensure 1Password Connect server is running and accessible, and environment variables are correct.")

view raw JSON →