Skip to main content

s6r-bitwarden-cli

Interact easily with Bitwarden client.

Overview

s6r-bitwarden-cli is a Python script designed to provide a convenient interface for interacting with the Bitwarden command-line interface (CLI) tool. It allows users to perform various Bitwarden actions, such as logging in, searching for items, retrieving item details, collections, organizations, directly from within a Python script.

Table of Contents

Installation

    pip install s6r-bitwarden-cli

Make sure you have already logged for the first time with bw:

bw login

Install Bitwarden CLI

Make sure to install the Bitwarden CLI tool on your system. You can download it from the official Bitwarden website or use your package manager.

Download and install

Usage

from s6r_bitwarden_cli import BitwardenCli

bw_cli = BitwardenCli()
password = bw_cli.get_item_password('Staging', collection_name='My collection')

The get_item_password method, when used with correctly set environment variables, abstracts the complexities of Bitwarden authentication and CLI interactions, providing a seamless way to retrieve passwords for specified items.

Login to Bitwarden Vault

To log in to your Bitwarden Vault, you have multiple options based on your preferred authentication method.

Login with Username and Password

Set the following environment variables to log in using your Bitwarden username and password:

  • BITWARDEN_USERNAME: Your Bitwarden username.
  • BITWARDEN_PASSWORD: Your Bitwarden password.
export BITWARDEN_USERNAME=your_username
export BITWARDEN_PASSWORD=your_password

Login with API Key

If you prefer to use an API key for authentication, set the following environment variables:

  • BITWARDEN_API_CLIENT_ID: Your Bitwarden API client ID.
  • BITWARDEN_API_CLIENT_SECRET: Your Bitwarden API client secret.

Note: The BITWARDEN_PASSWORD environment variable is still required to unlock the vault, even when using API key authentication.

export BITWARDEN_API_CLIENT_ID=your_api_client_id
export BITWARDEN_API_CLIENT_SECRET=your_api_client_secret

Unlock with Session Key

If you are already logged in and have a session key, set the BITWARDEN_SESSION_KEY environment variable to unlock the vault.

This method allows you to bypass the username and password or API key authentication if you have an active session.

export BITWARDEN_SESSION_KEY=your_session_key

Examples

# Initialize Bitwarden CLI
from s6r_bitwarden_cli import BitwardenCli
bw = BitwardenCli(username='your_username', password='your_password', verbose=True)

# Check Bitwarden session status
status = bw.get_status()

# Perform login
bw.login()

# Unlock Bitwarden vault
bw.unlock()

# Search for Bitwarden items
items = bw.search_objects(objects='items', search='keyword')

# Retrieve details of a Bitwarden item
item_details = bw.get_item(name='item_name')

# Get username of a Bitwarden item
username = bw.get_item_username(name='item_name')

# Get value of a custom field of a Bitwarden item
my_custom_field = bw.get_item_field(name='item_name', field_name='my_custom_field')

# Get a list of Bitwarden organizations
organizations = bw.get_organizations()

# Get the default organization
default_organization = bw.get_default_organization()

# Get the ID of the default organization
default_organization_id = bw.get_default_organization_id()

# Get organization collections
org_collections = bw.get_org_collections(search='collection_name', organization_id='organization_id')

# Get an organization collection
org_collection = bw.get_org_collection(search='collection_name', organization_id='organization_id')

# Get the ID of an organization collection
org_collection_id = bw.get_org_collection_id(search='collection_name', organization_id='organization_id')

# logout from Bitwarden
bw.logout()

License

This project is licensed under the GNU Lesser General Public License (LGPL) Version 3.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

Contributors

Maintainer

This software is maintained by Scalizer.

Scaliser

Metadata

Release files for s6r-bitwarden-cli 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for s6r-bitwarden-cli 1.0.7
File Size Uploaded
s6r_bitwarden_cli-1.0.7.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for s6r-bitwarden-cli 1.0.7
File Interpreter ABI Platform
s6r_bitwarden_cli-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 24.4 kB

Release files / s6r_bitwarden_cli-1.0.7.tar.gz

Download URL s6r_bitwarden_cli-1.0.7.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
650d343af075dfe07f6fd3fbc97f8850d1b0204fac407a546ceb63af973f2f79
BLAKE2b-256 checksum
How to use checksums
6c4fe53b1e79c21b7f271f277e29e49a544a6aea58961ef95d7f32d3b08e3ed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / s6r_bitwarden_cli-1.0.7-py3-none-any.whl

Download URL s6r_bitwarden_cli-1.0.7-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f44d7b85be693309c669286963f77e63613ac697aeb7d387096295d2f68be4ef
BLAKE2b-256 checksum
How to use checksums
3a51a99d729cd1f7daa425ff9a5b3bba69e29d53a6a69c28fbb1cdc6c2b258e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.7 This release

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page