Skip to main content

Admin Vaultwarden and Simple Bitwarden Python Client

Project description

python-vaultwarden

PyPI Version Build Status

A python client library for vaultwarden.

Rationale

While there are numerous clients for bitwarden, its low-level Python client libraries ecosystem is not well stuffed yet.

We at Numberly are strong users (and supporters) of vaultwarden and needed a way to integrate admin operations into our automation stack.

We took inspiration from bitwardentools and leverage from it internally while adding some admin related features so that we can automate vaultwarden administration tasks.

Contributions welcomed!

Clients

There are 2 types of clients:

  • One for the vaultwarden admin API, that needs to be authenticated with an admin token.
  • One for the bitwarden API, that needs to be authenticated with the user api keys or user's mail and password. An Owner or Admin user is required to perform admin operations.

The reset_account and transfer_account_rights from the Admin client needs a valid Bitwarden client to re-invite the target user.

Usage

Admin client

from vaultwarden.clients.vaultwarden import VaultwardenAdminClient

client = VaultwardenAdminClient(url="https://vaultwarden.example.com", admin_secret_token="admin_token")

client.invite("john.doe@example.com")

all_users = client.get_all_users()

client.delete(all_users[0].id)

Bitwarden client

from vaultwarden.clients.bitwarden import BitwardenAPIClient
from vaultwarden.models.bitwarden import Organization, OrganizationCollection, get_organization

bitwarden_client = BitwardenAPIClient(url="https://vaultwarden.example.com", email="admin@example", password="admin_password", client_id="client_id", client_secret="client_secret")

org_uuid = "550e8400-e29b-41d4-a716-446655440000"

orga= get_organization(bitwarden_client, org_uuid)

collection_id_list = ["666e8400-e29b-41d4-a716-446655440000", "888e8400-e29b-41d4-a716-446655440000", "770e8400-e29b-41d4-a716-446655440000" ]
orga.invite(email="new@example.com", collections=collection_id_list, default_readonly=True, default_hide_passwords=True)
org_users = orga.users()
org_collections: list[OrganizationCollection] = orga.collections()
org_collections_by_name: dict[str: OrganizationCollection] = orga.collections(as_dict=True)
new_coll = orga.create_collection("new_collection")
orga.delete_collection(new_coll.Id)

my_coll = orga.collection("my_collection")
if new_coll:
    users_coll = my_coll.users()

my_coll_2 = org_collections_by_name["my_coll_2"]

my_user = orga.users(search="john.doe@example.com")
if my_user:
    my_user = my_user[0]
    print(my_user.Collections)
    my_user.add_collections([my_coll_2.Id])

TODO

  • Add tests form Vaultwarden admin client
  • Rewrite crypto part to remove dependency on bitwardentools and add argon2id support
  • Support email + password authentication
  • Support end user operations
  • Ciphers management support
  • Many other things I didn't think of yet

Credits

The crypto part originates from bitwardentools.

License

Python-vaultwarden is distributed under the terms of the Apache-2.0 license.

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

python_vaultwarden-1.0.1rc1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

python_vaultwarden-1.0.1rc1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file python_vaultwarden-1.0.1rc1.tar.gz.

File metadata

File hashes

Hashes for python_vaultwarden-1.0.1rc1.tar.gz
Algorithm Hash digest
SHA256 c136c1344f0b3c4b9ec3d6e10b8c79d2b745d3d5c748f92c1afadc2c65c8859b
MD5 dca7006f54c67dca6b767e90432fce3f
BLAKE2b-256 3ce6285b66c61e1e2dca731a6704575bd45483468ef92c44c2afaadd46cbf7a0

See more details on using hashes here.

File details

Details for the file python_vaultwarden-1.0.1rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_vaultwarden-1.0.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2ab6592aeedae36f12af338f7133ab16d87b0419ccc2da2f9ef5667e4632056
MD5 8e94f2bbc51b3483f1988b010d4b3242
BLAKE2b-256 d9c7d3e5b7c9490cf57bcf2023ba5121c5675559f497687c8eeeb05966e910a8

See more details on using hashes here.

Supported by

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