OnePassword CLI v2 python wrapper
Simple python wrapper for the 1password cli version 2.
Setup
- Install the
opcli by following these instructions. - Make sure you have
opin your PATH and that it is not version 1
$ op --version
2.12.0
- Have your 1password username, password, and signin url handy
pip install onepassword2
or, for a local install
make local_install
If, for some reason python-Levenshtein fails to compile, skip it
pip install fuzzywuzzy && pip install --no-deps onepassword2
Usage
CLI
The op cli tool has a lot of options for managing multiple accounts, profiles, etc. Sessions opened with the cli terminate after 10 minutes, requiring the user to re-authenticate interactively. This is good security. However, if you need long running, non-interactive usage, it's a hindrance. onepassword2 comes with a handy CLI to automagify the signin process.
export OP_ACCOUNT='user@example.com'
export OP_PASSWORD="your password"
export OP_HOSTNAME="my.1password.com"
export OP_SECRET_KEY="JA-EKJHGQ-LKIUHG-12345-12345-12345-32154"
eval $(op-signin)
...
$ op vault list
ID NAME
naaizerttzertzefzyhjroeqrq Private
In python scripts
username = "user@example.com"
password = "your password"
hostname = "yourhost.1password.com"
secret_key = "JA-EKJHGQ-LKIUHG-12345-12345-12345-32154"
from onepassword2 import OP2
o = OP2( username, password, secret_key, hostname)
o.signin()
for v in o.vaults():
print(v)
List items
for d in o.items():
print(d)
Get a single item as a python dictionary
item = o.item("my item")
print(item)
Get a single item as an OP2Item object with handy methods to modify fields
from onepassword2 import OP2, OP2Item
item = OP2Item(o, "my item")
item.set("notesPlain", "new value for notes")
item.save()
If more than one item has the same name, you'll get a MultipleMatchesException
from onepassword2 import OP2, OP2Item, MultipleMatchesException
item1 = OP2Item(o)
item1.set("title", "my handy item")
item1.set("notesPlain", "new value for notes")
item1.save()
item2 = OP2Item(o)
item2.set("title", "my handy item")
item2.set("notesPlain", "hahaha same title, different content")
item2.save()
try:
item = OP2Item(o, "my item")
print(item)
except MultipleMatchesException:
for i in o.items("my item"):
item = OP2Item(o, i["id"])
...
Make a new secure note
from onepassword2 import OP2, OP2Item
item = OP2Item(o)
item.set("title", "my note")
item.set("notesPlain", "new value for notes")
item.save()
If you have more than one vault, you'll need to specify which one to save the secure note to:
from onepassword2 import OP2, OP2Item, OP2Vault
v = OP2Vault(o)
v.name("my new vault")
v.save()
item = OP2Item(o)
item.set("title", "my note")
item.set("vault", "my new vault")
item.set("notesPlain", "new value for notes")
item.save()
Example username/password combo:
item = OP2Item(o)
item.set("title", "my account")
item.set('url', "http://example.com")
item.set('username', "username@example.com")
item.set('password', "321657PASKJHKUH")
# urls can also have notes
item.set('notesPlain', "notes here")
# tags can be set as an array
item.set('tags', ["tags", "go", "here"])
item.save()
Metadata
Release files for onepassword2 1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onepassword2-1.7.tar.gz | 5.8 kB | Without provenance | Details for onepassword2-1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onepassword2-1.7-py3-none-any.whl | Python 3 | none | any | Details for onepassword2-1.7-py3-none-any.whl |
Total release size: 11.8 kB
Release files / onepassword2-1.7.tar.gz
| Download URL | onepassword2-1.7.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5ea72319377177fd62c6d117daaa97392f53a083dd402c37a1afd38e31a5184
|
|
BLAKE2b-256 checksum How to use checksums |
20f4e259a1d32a868cd3af77c95aa29538ac558be8d268f4017fbddd6f775d35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.7
|
Release files / onepassword2-1.7-py3-none-any.whl
| Download URL | onepassword2-1.7-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9ede95a75aa44ab9cea64dd424f3a76c98c4a92c98f7ba44a58680b8ab065c0
|
|
BLAKE2b-256 checksum How to use checksums |
f21a24586b2348d47344773ae954e12a240830840ff1609784d3806a536da254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.7
|
Security for onepassword2 1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.