Package: onepasswordconnectsdkopexe
1Password Connect Python SDK with OP.exeThe 1Password Connect SDK with OP.exe provides access to 1Password via1Password command-line toolhosted in your infrastructure. The library is intended to be used by Python applications to simplify accessing items in 1Password vaults.InstallationTo install the 1Password Connect Python SDK:$pipinstallonepasswordconnectsdkopexeTo install a specific release of the 1Password Connect Python SDK:$pipinstallonepasswordconnectsdkopexe==1.0.1UsageImport 1Password Connect Python SDKimportonepasswordconnectsdkopexeEnvironment VariablesOP_ACCOUNT- Account 1PasswordOP_CONNECT_HOST- The hostname of the 1Password Connect API.
Possible values include:connect-api:8080if the Connect server is running in the same Kubernetes cluster as your application.localhost:8080if the Connect server is running in Docker on the same host.<ip>:8080or<hostname>:8080if 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 1PasswordOP_MASTER_PASSWORD- Master password of previous loginOP_SECRET_KEY- Sercret key of previous loginCreate a ClientThere 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 theOP_CONNECT_TOKENandOP_CONNECT_HOSTenvironment variables.new_client: Builds a new client to interact with 1Password without checking past parameter values.fromonepasswordconnectsdk.clientimport(Client,new_client_interactif,new_client)# creation client by asking him the different parametersclient_from_env:Client=new_client_interactif()# creates a client by supplying hostname and 1Password Connect API tokenclient_from_token:Client=new_client("{1Password_CONNECT_HOST}","{1Password_account}","{1Password_email}","{1Password_secret_key}","{1Password_master_password}")Get ItemGet a specific item by item and vault ids:client.get_item("{item_id}","{vault_id}")Get Item By TitleGet a specific item by item title and vault id:client.get_item_by_title("{item_title}","{vault_id}")Get All ItemsGet a summarized list of all items for a specified vault:client.get_items("{vault_id}")Delete ItemDelete an item by item and vault ids:client.delete_item("{item_id}","{vault_id}")Create ItemCreate an item in a specified vault:fromonepasswordconnectsdkopexe.modelsimportOPItemVaultasItemVaultfromonepasswordconnectsdkopexe.modelsimportOPFieldasField# 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 ItemUpdate the item identified by the specified item and vault ids. The existing item will be overwritten with the newly supplied item.fromonepasswordconnectsdkopexe.modelsimportOPItemVaultasItemVaultfromonepasswordconnectsdkopexe.modelsimportOPFieldasField# 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 VaultGet a vault by vault id:client.get_vault("{vault_id}")Get VaultsRetrieve all vaults available to the service account:client.get_vaults()Load ConfigurationUsers can createclassesordictsthat 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 1Passwordload: 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)classConfig:server:'opitem:"My database item" opvault:some_vault_id opfield:specific_section.hostname'=Nonedatabase:'opitem:"My database item" opfield:.database'=Noneusername:'opitem:"My database item" opfield:.username'=Nonepassword:'opitem:"My database item" opfield:.password'=NoneCONFIG=Config()values_object=onepasswordconnectsdk.load(CONFIG)