The 1Password Python SDK is compatible with:
python
3.9 or laterlibssl
3glibc
2.32 or later
If 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:
-
Create a service account and give it the appropriate permissions in the vaults where the items you want to use with the SDK are saved.
-
Provision your service account token. We recommend provisioning your token from the environment. For example, to export your token to the
OP_SERVICE_ACCOUNT_TOKEN
environment variable:macOS or Linux
export OP_SERVICE_ACCOUNT_TOKEN=<your-service-account-token>
Windows
$Env:OP_SERVICE_ACCOUNT_TOKEN = "<your-service-account-token>"
-
Install the 1Password Python SDK in your project:
pip install onepassword-sdk
-
Use the Python SDK in your project:
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:
- Retrieve secrets
- Retrieve items
- Create items
- Update items
- Delete items
- List items
- Add & update tags on items
Field types:
- API Keys
- Passwords
- Concealed fields
- Text fields
- Notes
- SSH private keys (partially supported: supported in resolving secret references, not yet supported in item create/get/update)
- SSH public keys, fingerprint and key type
- One-time passwords
- URLs
- Websites (used to suggest and autofill logins)
- Phone numbers
- Credit card types
- Files attachments and Document items
- Retrieve vaults
- Create vaults (#36)
- Update vaults
- Delete vaults
- List vaults
- Provision users
- Retrieve users
- List users
- Suspend users
- Create groups
- Update group membership
- Update vault access & permissions
- Watchtower insights
- Travel mode
- Events. For now, use 1Password Events Reporting API directly.
- 1Password Service Accounts
- User authentication
- 1Password Connect. For now, use 1Password/connect-sdk-python.