Skip to main content

1Password Connect Python SDK with OP.exe

The 1Password Connect SDK with OP.exe provides access to 1Password via 1Password command-line tool hosted in your infrastructure. The library is intended to be used by Python applications to simplify accessing items in 1Password vaults.

Installation

To install the 1Password Connect Python SDK:

$ pip install onepasswordconnectsdkopexe

To install a specific release of the 1Password Connect Python SDK:

$ pip install onepasswordconnectsdkopexe==1.0.1

Usage

Import 1Password Connect Python SDK

import onepasswordconnectsdkopexe

Environment Variables

  • OP_ACCOUNT - Account 1Password
  • OP_CONNECT_HOST - The hostname of the 1Password Connect API. Possible values include:
    • connect-api:8080 if the Connect server is running in the same Kubernetes cluster as your application.
    • localhost:8080 if the Connect server is running in Docker on the same host.
    • <ip>:8080 or <hostname>:8080 if the Connect server is running on another host.
  • OP_VAULT - The default vault to fetch items from if not specified.
  • OP_EMAIL_ADDRESS - User login of 1Password
  • OP_MASTER_PASSWORD - Master password of previous login
  • OP_SECRET_KEY - Sercret key of previous login

Create a Client

There are two methods available for creating a client:

  • new_client_interactif: Builds a new client for interacting with 1Password Connect. Accepts the hostname, the account, the email address of user, the master password and the secret key of the connection at 1Password if the values are not passed in parameter. Builds a new client for interacting with 1Password Connect using the OP_CONNECT_TOKEN and OP_CONNECT_HOST environment variables.
  • new_client: Builds a new client to interact with 1Password without checking past parameter values.
from onepasswordconnectsdk.client import (
    Client,
    new_client_interactif,
    new_client
)

# creation client by asking him the different parameters
client_from_env: Client = new_client_interactif()

# creates a client by supplying hostname and 1Password Connect API token
client_from_token: Client = new_client(
    "{1Password_CONNECT_HOST}",
    "{1Password_account}",
    "{1Password_email}",
    "{1Password_secret_key}",
    "{1Password_master_password}")
    

Get Item

Get a specific item by item and vault ids:

client.get_item("{item_id}", "{vault_id}")

Get Item By Title

Get a specific item by item title and vault id:

client.get_item_by_title("{item_title}", "{vault_id}")

Get All Items

Get a summarized list of all items for a specified vault:

client.get_items("{vault_id}")

Delete Item

Delete an item by item and vault ids:

client.delete_item("{item_id}", "{vault_id}")

Create Item

Create an item in a specified vault:

from onepasswordconnectsdkopexe.models import OPItemVault as ItemVault
from onepasswordconnectsdkopexe.models import OPField as Field

# Example item creation. Create an item with your desired arguments. 
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
                                      id="kp2td65r4wbuhocwhhijpdbfqq",
                                      title="newtitle",
                                      category="LOGIN",
                                      tags=["1password-connect"],
                                      fields=[Field(value="new_user",
                                      purpose="USERNAME")],
                                      )
client.create_item("{vault_id}", item)

Update Item

Update the item identified by the specified item and vault ids. The existing item will be overwritten with the newly supplied item.

from onepasswordconnectsdkopexe.models import OPItemVault as ItemVault
from onepasswordconnectsdkopexe.models import OPField as Field

# Example item creation. Create an item with your desired arguments. 
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="av223f76ydutdngislnkbz6z5u"),
                                      id="kp2td65r4wbuhocwhhijpdbfqq",
                                      title="newtitle",
                                      category="LOGIN",
                                      tags=["1password-connect"],
                                      fields=[Field(value="new_user",
                                      purpose="USERNAME")],
                                      )
client.update_item("{item_id}", "{vault_id}", item)

Get Specific Vault

Get a vault by vault id:

client.get_vault("{vault_id}")

Get Vaults

Retrieve all vaults available to the service account:

client.get_vaults()

Load Configuration

Users can create classes or dicts that describe fields they wish to get the values from in 1Password. Two convienience methods are provided that will handle the fetching of values for these fields:

  • load_dict: Takes a dictionary with keys specifying the user desired naming scheme of the values to return. Each key's value is a dictionary that includes information on where to find the item field value in 1Password. This returns a dictionary of user specified keys with values retrieved from 1Password
  • load: Takes an object with class attributes annotated with tags describing where to find desired fields in 1Password. Manipulates given object and fills attributes in with 1Password item field values.
# example dict configuration for onepasswordconnectsdk.load_dict(CONFIG)
CONFIG = {
    "server": {
        "opitem": "My database item",
        "opfield": "specific_section.hostname",
        "opvault": "some_vault_id",
    },
    "database": {
        "opitem": "My database item",
        "opfield": ".database",
    },
    "username": {
        "opitem": "My database item",
        "opfield": ".username",
    },
    "password": {
        "opitem": "My database item",
        "opfield": ".password",
    },
}

values_dict = onepasswordconnectsdk.load_dict(CONFIG)
# example class configuration for onepasswordconnectsdk.load(CONFIG)
class Config:
    server: 'opitem:"My database item" opvault:some_vault_id opfield:specific_section.hostname' = None
    database: 'opitem:"My database item" opfield:.database' = None
    username: 'opitem:"My database item" opfield:.username' = None
    password: 'opitem:"My database item" opfield:.password' = None

CONFIG = Config()

values_object = onepasswordconnectsdk.load(CONFIG)

Metadata

Release files for onepasswordconnectsdkopexe 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onepasswordconnectsdkopexe 0.1.5
File Size Uploaded
onepasswordconnectsdkopexe-0.1.5.tar.gz 3.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for onepasswordconnectsdkopexe 0.1.5
File Interpreter ABI Platform
onepasswordconnectsdkopexe-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 MB

Release files / onepasswordconnectsdkopexe-0.1.5.tar.gz

Download URL onepasswordconnectsdkopexe-0.1.5.tar.gz
Size 3.9 MB
Tags Source
SHA-256 checksum
How to use checksums
a2f52e9e32bc2e3547b1b73d0ba50cd18a16f046dadbddb235c6fc3795fdcaee
BLAKE2b-256 checksum
How to use checksums
617ad83b51ba2e9dea9965a85995c1b62889599a297c69cd372f0e10221db52a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.7 Windows/10

Release files / onepasswordconnectsdkopexe-0.1.5-py3-none-any.whl

Download URL onepasswordconnectsdkopexe-0.1.5-py3-none-any.whl
Size 3.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b24d194ce6409acb3d24c82971f98abd9dc5143da183e4067e09ac3655975a35
BLAKE2b-256 checksum
How to use checksums
f7c42a1a703b65174a935901d671f7162aabb60ca1532a18303e06a949096e25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.7 Windows/10

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page