Skip to main content

A Python wrapper for the Bitwarden CLI — programmatically manage your Bitwarden vault: create, read, edit and delete items, folders, collections, attachments, and more.

Project description

bitwarden-py

A Python wrapper for the Bitwarden CLI — programmatically manage your Bitwarden vault: create, read, edit and delete items, folders, collections, attachments, and more.

PyPI - Python Version PyPI - Version Code style: black Linting: Ruff uv GitHub License


Requirements

Bitwarden CLI

bitwarden-py calls the official bw binary under the hood, so you must have it installed and available in your PATH.

Install it by following the official guide:
👉 https://bitwarden.com/help/cli/#download-and-install

Quick install options:

# macOS (Homebrew)
brew install bitwarden-cli

# Windows (Chocolatey)
choco install bitwarden-cli

# npm (cross-platform)
npm install -g @bitwarden/cli

After installation, verify it works:

bw --version

Installation

pip install bitwarden-py

Or with uv:

uv add bitwarden-py

Quick Start

from bitwarden_py import Bitwarden

bw = Bitwarden(
    email="your@email.com",
    password="your_master_password",
)

# Fetch a password by item name
db_password = bw.get_password("My Database")
print(db_password)  # → "s3cr3t!"

# Update the password of an item
bw.set_password("My Database", "n3wp4ssw0rd")

Using a self-hosted server

By default the library points to https://vault.bitwarden.eu.
Pass server_url to connect to a different instance:

bw = Bitwarden(
    email="your@email.com",
    password="your_master_password",
    server_url="https://bitwarden.yourcompany.com",
)

API Reference

For the full Bitwarden CLI documentation, see 👉 https://bitwarden.com/help/cli/

Bitwarden(email, password, server_url?)

Creates a new client and authenticates with the vault.

Parameter Type Default Description
email str Your Bitwarden account email
password str Your master password
server_url str "https://vault.bitwarden.eu" Bitwarden server URL

Create

bw.create_item(item) → dict

Creates a new vault item. Use bw.get_template("item") to obtain the base structure.

template = bw.get_template("item")
template["name"] = "My Login"
template["login"]["username"] = "user@example.com"
template["login"]["password"] = "s3cr3t"
new_item = bw.create_item(template)

bw.create_folder(folder) → dict

Creates a new folder. Use bw.get_template("folder") to obtain the base structure.

template = bw.get_template("folder")
template["name"] = "Work"
new_folder = bw.create_folder(template)

bw.create_attachment(file_path, item_id) → dict

Attaches a file to an existing vault item.

bw.create_attachment("./secret.txt", "16b15b89-65b3-4639-ad2a-95052a6d8f66")

Read

bw.get_password(item_name) → str

Returns the password of the vault item matching item_name.

bw.get_item(id_or_name) → dict

Returns the full vault item object matching the given ID or name.

bw.get_username(id_or_name) → str

Returns the username of the vault item matching the given ID or name.

bw.get_notes(id_or_name) → str

Returns the notes of the vault item matching the given ID or name.

bw.get_uri(id_or_name) → str

Returns the URI of the vault item matching the given ID or name.

bw.get_totp(id_or_name) → str

Returns the current TOTP code for the vault item matching the given ID or name.

bw.get_template(object_type) → dict

Returns the JSON template for the given object type. Useful for constructing objects to pass to create_* and edit_* methods.

Supported types: item, item.field, item.login, item.login.uri, item.card, item.identity, item.securenote, folder, collection, item-collections, org-collection.

bw.list_items(search?, folder_id?, collection_id?, organization_id?, url?, trash?) → list[dict]

Returns a list of vault items. All parameters are optional and act as filters.

Parameter Type Description
search str Filter by search term
folder_id str Filter by folder ID (null / notnull)
collection_id str Filter by collection ID
organization_id str Filter by organization ID
url str Filter by URI
trash bool If True, list items in the trash

bw.list_folders(search?) → list[dict]

Returns a list of folders, optionally filtered by search.

bw.list_collections(organization_id?, search?) → list[dict]

Returns a list of collections, optionally filtered by organization ID or search term.

bw.list_organizations(search?) → list[dict]

Returns a list of organizations, optionally filtered by search.


Edit

bw.edit_password(item_name, new_password) → None

Updates the password of the vault item matching item_name.

bw.edit_item(item_id, item) → dict

Replaces a vault item with the provided dict. Fetch the current item with get_item first, modify it, then pass it here.

item = bw.get_item("7ac9cae8-5067-4faf-b6ab-acfd00e2c328")
item["login"]["password"] = "newp@ssw0rd"
bw.edit_item(item["id"], item)

bw.edit_folder(folder_id, folder) → dict

Replaces a folder with the provided dict.


Delete

bw.delete_item(item_id, permanent?) → None

Sends an item to the trash. Pass permanent=True to delete it immediately without going through trash.

bw.delete_folder(folder_id, permanent?) → None

Deletes a folder. Pass permanent=True to skip trash.

bw.delete_attachment(attachment_id, item_id) → None

Deletes an attachment from a vault item.


Session

bw.logout() → None

Logs out of the Bitwarden vault and clears the local session.

bw.sync() → None

Downloads the encrypted vault from the Bitwarden server. Useful when you have made changes in another Bitwarden client (web vault, browser extension, mobile app) and want the CLI to reflect the latest state.


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitwarden_py-0.3.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bitwarden_py-0.3.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file bitwarden_py-0.3.1.tar.gz.

File metadata

  • Download URL: bitwarden_py-0.3.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bitwarden_py-0.3.1.tar.gz
Algorithm Hash digest
SHA256 04cd04886147cb1b100e3c92bfe2378defdc97845b2876f4f837a1338f346a0a
MD5 d0dfa83d5190e073090ba4d36da7d216
BLAKE2b-256 60cd75eec6e8c7324ab8189d6cc690d66b449e1b7b0c645a61e1c16f3ac6f621

See more details on using hashes here.

File details

Details for the file bitwarden_py-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: bitwarden_py-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bitwarden_py-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3c2052a12160120522333010c01fcd6e63b9c87ec5711593c63e7962b238e42
MD5 12accd973a1b182f0b9fe36a4712054f
BLAKE2b-256 1aa6dccc95b5049433395464374037f92e4c588a937595dd2c2d9761720deea3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page