BWS SDK (Bitwarden Secrets SDK)
A pure Python implementation of the Bitwarden Secrets Manager API, allowing secure access to and management of Bitwarden secrets.
Overview
BWS SDK provides a simple, Pythonic interface to interact with the Bitwarden Secrets Manager. It handles authentication, decryption, and secure communication with the Bitwarden API, allowing you to easily integrate Bitwarden Secrets into your Python applications.
Features
- Secure authentication with Bitwarden Secrets Manager
- Automatic decryption of secrets (encryption not yet supported)
- Optional state persistence for improved performance
- Support for different Bitwarden regions
- Synchronization capabilities for efficient secret updates
- Comprehensive error handling
Installation
# Using pip
pip install bws-sdk
# Using poetry
poetry add bws-sdk
Quick Start
from bws_sdk import BWSecretClient, Region
from datetime import datetime
# Define the Bitwarden region
region = Region(
api_url="https://api.bitwarden.com",
identity_url="https://identity.bitwarden.com"
)
# Create a client instance with your access token
# Optionally provide a state file path for token persistence
client = BWSecretClient(
region=region,
access_token="your-access-token",
state_file="./path/to/state.file" # Optional
)
# Retrieve a secret by ID
secret = client.get_by_id("your-secret-id")
print(f"Secret key: {secret.key}")
print(f"Secret value: {secret.value}")
# Sync secrets updated since a specific time
last_sync_date = datetime.fromisoformat("2025-01-01T00:00:00")
updated_secrets = client.sync(last_sync_date)
for secret in updated_secrets:
print(f"Updated secret: {secret.key}")
API Reference
BWSecretClient
The main client class for interacting with the Bitwarden Secrets Manager API.
Constructor
BWSecretClient(region: Region, access_token: str, state_file: str | None = None)
region: ARegionobject specifying the API endpointsaccess_token: Your Bitwarden access tokenstate_file: Optional path to a file for persisting authentication state
Methods
get_by_id(secret_id: str) -> BitwardenSecret: Retrieves a secret by its IDsync(last_synced_date: datetime) -> list[BitwardenSecret]: Retrieves secrets updated since the specified date
Note: The SDK currently only supports decryption of secrets. Methods for creating and encrypting new secrets are planned for future releases.
Region
A class representing a Bitwarden region configuration.
Region(api_url: str, identity_url: str)
api_url: The base URL for the region's API endpointidentity_url: The URL for the region's identity service
Error Types
UnauthorisedError: Raised when authentication failsInvalidTokenError: Raised when the provided token is invalidSecretParseError: Raised when a secret cannot be parsed or decryptedHmacError: Raised when MAC verification fails during decryption
Examples
Using Environment Variables for Secrets
import os
from bws_sdk import BWSecretClient, Region
# Get access token from environment variable
access_token = os.environ.get("BITWARDEN_ACCESS_TOKEN")
# Define the region
region = Region(
api_url="https://api.bitwarden.com",
identity_url="https://identity.bitwarden.com"
)
# Create the client
client = BWSecretClient(region, access_token)
# Retrieve a secret
secret = client.get_by_id(os.environ.get("SECRET_ID"))
print(f"Retrieved secret: {secret.key}")
Error Handling
from bws_sdk import BWSecretClient, Region, UnauthorisedError, SecretParseError
region = Region(
api_url="https://api.bitwarden.com",
identity_url="https://identity.bitwarden.com"
)
try:
client = BWSecretClient(region, "your-access-token")
secret = client.get_by_id("your-secret-id")
print(f"Secret retrieved: {secret.key}")
except UnauthorisedError:
print("Authentication failed. Please check your access token.")
except SecretParseError:
print("Failed to parse or decrypt the secret.")
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
References
Metadata
Release files for bws-sdk 2.0.0
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 |
|---|---|---|---|---|
| bws_sdk-2.0.0.tar.gz | 18.2 kB | With provenance | Details for bws_sdk-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bws_sdk-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for bws_sdk-2.0.0-py3-none-any.whl |
Total release size: 38.6 kB
Release files / bws_sdk-2.0.0.tar.gz
| Download URL | bws_sdk-2.0.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20347942a66c1ce82082c1dc1dbd22b876082b8551b07d4229514eb28a160583
|
|
BLAKE2b-256 checksum How to use checksums |
f238b77b02369facee61119ad10736804d96846f718b6d7e107cb21596c85db7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logRelease files / bws_sdk-2.0.0-py3-none-any.whl
| Download URL | bws_sdk-2.0.0-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2efd6521afb0e0fc321bcf07ab90946af834a96954e4235833500dd076abc628
|
|
BLAKE2b-256 checksum How to use checksums |
a16b7c2107e73a997a950e49829007b4bab2cda9bb42e8731b7826d8a85c1b8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logSecurity for bws-sdk 2.0.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bws_sdk-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 17, 2025.
Transparency logA 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.