The 1Password Python SDK is compatible with:
python 3.9 or laterlibssl 3glibc 2.32 or laterIf you're running a Linux distribution that still uses libssl version 1.1.1, such as Debian 11 or Ubuntu 20.04, you'll need to update to a later version of Linux or install the required dependencies.
To use the 1Password Python SDK in your project:
OP_SERVICE_ACCOUNT_TOKEN environment variable:macOS or Linux
bash
export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
Windows
powershell
$Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
bash
pip install onepassword-sdk
import asyncio
import os
from onepassword.client import Client
async def main():
# Gets your service account token from the OP_SERVICE_ACCOUNT_TOKEN environment variable.
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN")
# Connects to 1Password. Fill in your own integration name and version.
client = await Client.authenticate(auth=token, integration_name="My 1Password Integration", integration_version="v1.0.0")
# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.
value = await client.secrets.resolve("op://vault/item/field")
# use value here
if __name__ == '__main__':
asyncio.run(main())
Make sure to use secret reference URIs with the syntax op://vault/item/field to securely load secrets from 1Password into your code.
1Password SDKs are in active development. We're keen to hear what you'd like to see next. Let us know by upvoting or filing an issue.
Operations:
Field types: - [x] API Keys - [x] Passwords - [x] Concealed fields - [x] Text fields - [x] Notes - [x] SSH private keys, public keys, fingerprint and key type - [x] One-time passwords - [x] URLs - [x] Websites (used to suggest and autofill logins) - [x] Phone numbers - [x] Credit card types - [x] Credit card numbers - [x] Emails - [x] References to other items - [x] Address - [x] Date - [x] MM/YY - [x] File attachments and Document items - [x] Menu - [ ] Passkeys
$ claude mcp add onepassword-sdk-python \
-- python -m otcore.mcp_server <graph>