Forum Discussion

Former Member's avatar
Former Member
4 years ago

Issues Starting Out With Onepassword Connect & Python

Good evening all,
I hope this post reaches you in good health!
I am currently working on automating onepassword secrets via Python. I have the onepassword connector up & running & I can successfully pull information from it via curl as shown on this https://developer.1password.com/docs/connect/get-started/. I also have the onepasswordconnectsdk installed via pip. However, when I attempt to test out a write to a vault via a copied & pasted section of code from the "Create Item" section present in the https://github.com/1Password/connect-sdk-python/blob/main/README.md I receive an error stating:

NameError: name 'onepasswordconnectsdk' is not defined.
I am not sure why this is - everything looks good on my end & I can even pull vault information with this script, but I cannot create items. The following is the code I am using:
def onepass():
client_from_token: Client = new_client("http://local-ip-removed/", "token-removed")
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="vault-id-removed"),
id="test",
title="title",
category="LOGIN",
tags=["1password-connect"],
fields=[Field(value="new_user",
purpose="USERNAME")])
client.update_item("vault-id-removed", item)

Sorry for the code formatting, I was going to stick it in as "code" formatted but that made it all wonky.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

1 Reply

  • tyla's avatar
    tyla
    Icon for 1Password Team rank1Password Team

    Hey @nwhal,

    It seems like the problem is about importing the onepasswordconnectsdk. Try putting an import statement like this:


    import onepasswordconnectsdk
    from onepasswordconnectsdk.client import (Client, new_client)
    from onepasswordconnectsdk.models import (ItemVault, Field)

    Does this work for you?

    Thanks!