python-vaultwarden2 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_vaultwarden2-0.1.0.dist-info/METADATA +69 -0
- python_vaultwarden2-0.1.0.dist-info/RECORD +34 -0
- python_vaultwarden2-0.1.0.dist-info/WHEEL +4 -0
- python_vaultwarden2-0.1.0.dist-info/licenses/LICENSE +202 -0
- vaultwarden2/__init__.py +47 -0
- vaultwarden2/_async/__init__.py +1 -0
- vaultwarden2/_async/account.py +379 -0
- vaultwarden2/_async/admin.py +485 -0
- vaultwarden2/_async/auth.py +218 -0
- vaultwarden2/_async/base.py +462 -0
- vaultwarden2/_async/client.py +130 -0
- vaultwarden2/_async/organizations.py +914 -0
- vaultwarden2/_async/vault.py +970 -0
- vaultwarden2/_core.py +1103 -0
- vaultwarden2/_encode.py +422 -0
- vaultwarden2/_json.py +215 -0
- vaultwarden2/_merge.py +529 -0
- vaultwarden2/_offload.py +65 -0
- vaultwarden2/_sync/__init__.py +1 -0
- vaultwarden2/_sync/account.py +381 -0
- vaultwarden2/_sync/admin.py +487 -0
- vaultwarden2/_sync/auth.py +220 -0
- vaultwarden2/_sync/base.py +464 -0
- vaultwarden2/_sync/client.py +132 -0
- vaultwarden2/_sync/organizations.py +914 -0
- vaultwarden2/_sync/vault.py +968 -0
- vaultwarden2/crypto.py +634 -0
- vaultwarden2/dump.py +362 -0
- vaultwarden2/errors.py +123 -0
- vaultwarden2/export.py +128 -0
- vaultwarden2/models.py +842 -0
- vaultwarden2/py.typed +0 -0
- vaultwarden2/search.py +206 -0
- vaultwarden2/totp.py +214 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Do not edit this file directly. It has been autogenerated from
|
|
2
|
+
# src/vaultwarden2/_async/client.py
|
|
3
|
+
"""The public Vaultwarden client."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import functools
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
from vaultwarden2 import _offload, dump
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
from vaultwarden2.dump import Argon2Params, Compressor
|
|
16
|
+
from vaultwarden2.models import OrganizationRef
|
|
17
|
+
|
|
18
|
+
from . import organizations as _organizations_mod
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class VaultwardenClient(_organizations_mod.OrganizationsMixin):
|
|
22
|
+
"""Client for a Vaultwarden server: everything a user can do in the web vault.
|
|
23
|
+
|
|
24
|
+
All encryption happens on this machine; the server only sees ciphertext and the login hash. Create the client,
|
|
25
|
+
then log in with one of the two methods; both also unlock the vault, so decrypted items are available right away:
|
|
26
|
+
|
|
27
|
+
* [login_password][vaultwarden2.VaultwardenClient.login_password]``(email, password)``: email and master
|
|
28
|
+
password. Accounts with two-step login raise [TwoFactorRequiredError][vaultwarden2.TwoFactorRequiredError];
|
|
29
|
+
call again with ``two_factor_token=<code>``.
|
|
30
|
+
* [login_api_key][vaultwarden2.VaultwardenClient.login_api_key]``(client_id, client_secret, password)``:
|
|
31
|
+
the personal API key (from the web vault, or
|
|
32
|
+
[get_api_key][vaultwarden2.VaultwardenClient.get_api_key]) plus the master password, which is still
|
|
33
|
+
needed to decrypt the vault. Suited for automation.
|
|
34
|
+
|
|
35
|
+
Use the client as a context manager, or call ``close()`` when done.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
base_url: Address of the server, for example ``https://vault.example.org``. Plain ``http://`` to anything
|
|
39
|
+
but localhost triggers an [InsecureTransportWarning][vaultwarden2.InsecureTransportWarning].
|
|
40
|
+
timeout: Timeout for every HTTP request, in seconds.
|
|
41
|
+
verify: Verify the server's TLS certificate. Only disable for local testing.
|
|
42
|
+
device: How this client appears in the account's device list. Pass the same
|
|
43
|
+
[Device][vaultwarden2.Device] on every run so repeated runs count as one device and do not trigger
|
|
44
|
+
"new device" notifications. Defaults to a new random device.
|
|
45
|
+
http_client: A preconfigured httpx2 client (proxies, custom transports). Its ``base_url`` must point at the
|
|
46
|
+
server; it is closed together with this client.
|
|
47
|
+
|
|
48
|
+
Examples:
|
|
49
|
+
Email and master password, with the two-step login fallback:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import os
|
|
53
|
+
from vaultwarden2 import VaultwardenClient, TwoFactorRequiredError
|
|
54
|
+
|
|
55
|
+
with VaultwardenClient('https://vault.example.org') as vw:
|
|
56
|
+
try:
|
|
57
|
+
vw.login_password('me@example.org', os.environ['VW_PASSWORD'])
|
|
58
|
+
except TwoFactorRequiredError:
|
|
59
|
+
vw.login_password('me@example.org', os.environ['VW_PASSWORD'], two_factor_token=input('code: '))
|
|
60
|
+
for item in vw.search('github'):
|
|
61
|
+
print(item.name, item.login.username if item.login else '')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Personal API key plus master password, for scripts and services (no two-step prompt):
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import os
|
|
68
|
+
from vaultwarden2 import VaultwardenClient
|
|
69
|
+
|
|
70
|
+
with VaultwardenClient('https://vault.example.org') as vw:
|
|
71
|
+
vw.login_api_key(
|
|
72
|
+
os.environ['VW_CLIENT_ID'], # 'user.<uuid>'
|
|
73
|
+
os.environ['VW_CLIENT_SECRET'],
|
|
74
|
+
os.environ['VW_PASSWORD'], # still needed to decrypt the vault
|
|
75
|
+
)
|
|
76
|
+
item = vw.create_login('Example', username='alice', password='s3cr3t', uris=['https://example.org'])
|
|
77
|
+
```
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def dump_vault(
|
|
81
|
+
self,
|
|
82
|
+
path: str | os.PathLike[str],
|
|
83
|
+
passphrase: str,
|
|
84
|
+
*,
|
|
85
|
+
compressor: Compressor | None = None,
|
|
86
|
+
argon2: Argon2Params | None = None,
|
|
87
|
+
) -> None:
|
|
88
|
+
"""Write the personal vault to an encrypted, compressed backup file.
|
|
89
|
+
|
|
90
|
+
Contains the folders and personal items (archived ones included, items in the trash excluded) in the
|
|
91
|
+
JSON export format, compressed and encrypted with a key derived from ``passphrase``. Read it back with
|
|
92
|
+
[load_dump][vaultwarden2.dump.load_dump]. See [vaultwarden2.dump][] for the file format.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
path: The file to create. It must not exist yet; it is created with mode ``0600``.
|
|
96
|
+
passphrase: The passphrase protecting the file. It is the only protection: use a long one.
|
|
97
|
+
compressor: Compression module or object with ``compress``/``decompress`` (``gzip``, ``bz2``, ``lzma``,
|
|
98
|
+
...). Defaults to zstd when available, else lzma.
|
|
99
|
+
argon2: Cost of the passphrase key derivation. Defaults to RFC 9106 parameters (64 MiB, 3 passes).
|
|
100
|
+
|
|
101
|
+
Raises:
|
|
102
|
+
FileExistsError: ``path`` exists already.
|
|
103
|
+
CryptoError: The passphrase is empty.
|
|
104
|
+
"""
|
|
105
|
+
vault = self.sync(include_archived=True) # a backup must not drop archived items
|
|
106
|
+
_offload.run_cpu(functools.partial(dump.write_dump, compressor=compressor, argon2=argon2), vault, path, passphrase)
|
|
107
|
+
|
|
108
|
+
def dump_organization(
|
|
109
|
+
self,
|
|
110
|
+
organization: OrganizationRef,
|
|
111
|
+
path: str | os.PathLike[str],
|
|
112
|
+
passphrase: str,
|
|
113
|
+
*,
|
|
114
|
+
compressor: Compressor | None = None,
|
|
115
|
+
argon2: Argon2Params | None = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
"""Write an organization's collections and items to an encrypted, compressed backup file.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
organization: The organization, as object, id or unique name.
|
|
121
|
+
path: The file to create. It must not exist yet; it is created with mode ``0600``.
|
|
122
|
+
passphrase: The passphrase protecting the file.
|
|
123
|
+
compressor: Compression module or object with ``compress``/``decompress``. Defaults to zstd when
|
|
124
|
+
available, else lzma.
|
|
125
|
+
argon2: Cost of the passphrase key derivation. Defaults to RFC 9106 parameters.
|
|
126
|
+
|
|
127
|
+
Raises:
|
|
128
|
+
FileExistsError: ``path`` exists already.
|
|
129
|
+
CryptoError: The passphrase is empty, or an item cannot be decrypted.
|
|
130
|
+
"""
|
|
131
|
+
export = self.export_organization(organization)
|
|
132
|
+
_offload.run_cpu(functools.partial(dump.write_dump, compressor=compressor, argon2=argon2), export, path, passphrase)
|