pyonepassword 2.0, now with item creation

Options
zcutlip
zcutlip
Community Member

I'm pleased to share the release of pyonepassword 2.0. It's seen a lot of changes in the past few months, but the biggest is probably item creation. Previously you could only query existing entries, not create new ones. Currently only Login and Server items are supported, but more are planned.

Note: if Secrets Automation is a good fit for you, you should probably stick with that. But if you're currently using op on the command line or in shell scripts, but wish you had an API around all the JSON, pyonepassword may be worth looking into.

Here are a couple of examples of item creation:

Creating a Login Item

The OP class provides a convenience method to create a login item.

op = do_signin()
username = "testuser"
password = "testpass"
url = "https://example.website"
item_name = "login 3"

result: OPLoginItem
result = op.create_login_item(item_name, username, password, url=url)
# result is an actual OPLoginItem object queried from 1Password after item creation
# Among other things it provides the UUID of the created object
print(f"Item UUID: {result.uuid}")

Creating a Login Item with Custom Sections

Rather than use the convenience method, you may add custom sections and section fields to the item template before creation.

newlogin = OPLoginItemTemplate(username, password)

# user-visible section title is required
# section name (not user visible) is optional and will be randomly generated if not provided
#                 section title -----v                 v-------- section name
# section = newlogin.add_section("New Section", "new_section")
section = newlogin.add_section("New Section")

# field name is not user visible
# field label is user visible
section.add_field("example field name", "example value", "string", "example field label")

op.create_item(newlogin, "login 3")

Another noteworthy change is formal deprecation of initial sign-in. It is now expected that the user will have performed initial sign-in manually. Details about this, including rationale, can be found in the README.

More examples are in the README, and even more examples are in the examples folder in the source tree.

As usual you can install via pip:

pip3 install pyonepassword

Here's the project on GitHub:
https://github.com/zcutlip/pyonepassword

Cheers,
Zach


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

Comments

  • This is awesome, Zach! Thank you for sharing. ❤️

    Have you seen that we're working on a 2.0 of the CLI? I want to make sure you see these changes early and make sure you have everything you need to port the library as well. I've just granted you access to the Early Access and you can read more here. We're here to help if there's anything we can do.

This discussion has been closed.