It’s Cybersecurity Awareness Month! Join our interactive training session, or learn about security and AI from 1Password experts.
Forum Discussion
Former Member
3 years agoIs there a faster way to empty a vault using CLI2?
Hi, I have a requirement to empty certain vaults periodically and then refill them. I'd rather not delete the vault and recreate it and all the permissions if possible.
For a vault with 500 items ...
zcutlip
3 years agoDedicated Contributor
If doing this in python is an option for you, you could use pyonepassword for this. Tried it out just now, and have the (relatively minor) changes required implemented in a local branch. If useful. I could cut a release supporting this.
Example:
```python
from pyonepassword import OP
vault = "Test Vault"
op = OP()
item_list = op.item_list(vault=vault)
for item in item_list:
op.item_delete(item.unique_id, vault=vault)
```
Worth noting, we're deleting one item at a time, so it's about ~1 sec./item, so not super fast. Also I don't know if you'll hit any throttling issues from 1Password; each item_delete()
operation is actually two operations: a get (to resolve the unique ID) followed by a delete.
With moderately more effort, I could implement batch deletion where you could, say, delete 25 (or whatever number ends up working) items at a time.
So, similar to above, but maybe (this isn't implemented yet):
```python
from pyonepassword import OP
vault = "Test Vault"
op = OP()
item_list = op.item_list(vault=vault)
probably have a default batch size, but override with a kwarg?
op.item_delete_batch(item_list, vault=vault)
```
Let me know if either of those sounds useful.
The first option I could probably get out as soon as tonight. The second, wouldn't be too bad, but might take a week or so.
Zach