Skip to content

Commit 5f4452f

Browse files
committed
Update README with database creation and KDF documentation
- Add Python 3.11+ requirement to installation section - Document create_database() with KDBX3/KDBX4 version support - Document Cipher enum, Argon2Config, and AesKdfConfig options - Add section for modifying KDF parameters on existing databases - Update test instructions to use pytest - Fix typos in attachments section - Standardize section header formatting
1 parent 2c75068 commit 5f4452f

1 file changed

Lines changed: 91 additions & 11 deletions

File tree

README.md

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,76 @@
33
<a href="https://github.com/libkeepass/pykeepass/actions/workflows/ci.yaml"><img src="https://github.com/libkeepass/pykeepass/actions/workflows/ci.yaml/badge.svg"/></a>
44
<a href="https://libkeepass.github.io/pykeepass"><img src="https://readthedocs.org/projects/pykeepass/badge/?version=latest"/></a>
55
<a href="https://matrix.to/#/%23pykeepass:matrix.org"><img src="https://img.shields.io/badge/chat-%23pykeepass-green"/></a>
6-
7-
This library allows you to write entries to a KeePass database.
6+
7+
This library allows you to read and write KeePass databases (KDBX3 and KDBX4 formats).
88

99
Come chat at [#pykeepass:matrix.org](https://matrix.to/#/%23pykeepass:matrix.org) on Matrix.
1010

1111
# Installation
1212

13+
Requires Python 3.11+
14+
1315
``` bash
14-
sudo apt install python3-lxml
16+
pip install pykeepass
17+
```
18+
19+
On Debian/Ubuntu, you may need to install lxml dependencies first:
20+
21+
``` bash
22+
sudo apt install libxml2-dev libxmlsec1-dev
1523
pip install pykeepass
1624
```
1725

1826
# Quickstart
1927

20-
General database manipulation
28+
## Creating a Database
29+
30+
``` python
31+
from pykeepass import create_database
32+
33+
# create a new KDBX4 database with default settings (Argon2id, AES-256)
34+
>>> kp = create_database('new.kdbx', password='somePassw0rd')
35+
36+
# create with a keyfile
37+
>>> kp = create_database('new.kdbx', password='somePassw0rd', keyfile='key.key')
38+
39+
# create a KDBX3 database
40+
>>> kp = create_database('new.kdbx', password='somePassw0rd', version=3)
41+
```
42+
43+
### Cipher and KDF Options
44+
45+
``` python
46+
from pykeepass import create_database
47+
from pykeepass.kdbx_parsing import Cipher, Argon2Config, AesKdfConfig
48+
49+
# KDBX4 with ChaCha20 cipher and custom Argon2 settings
50+
>>> kp = create_database(
51+
... 'new.kdbx',
52+
... password='somePassw0rd',
53+
... cipher=Cipher.chacha20,
54+
... kdf=Argon2Config(iterations=5, memory=131072, parallelism=4, variant='id'),
55+
... )
56+
57+
# use preset configurations
58+
>>> kp = create_database('new.kdbx', password='pw', kdf=Argon2Config.high_security())
59+
>>> kp = create_database('new.kdbx', password='pw', kdf=Argon2Config.fast())
60+
61+
# KDBX3 with Twofish cipher and custom AES-KDF rounds
62+
>>> kp = create_database(
63+
... 'new.kdbx',
64+
... password='somePassw0rd',
65+
... version=3,
66+
... cipher=Cipher.twofish,
67+
... kdf=AesKdfConfig(rounds=100000),
68+
... )
69+
```
70+
71+
Available ciphers: `aes256`, `chacha20`, `twofish`
72+
73+
Available Argon2 variants (KDBX4): `id`, `d`, `i`
74+
75+
## Opening and Manipulating Databases
2176

2277
``` python
2378
from pykeepass import PyKeePass
@@ -59,7 +114,7 @@ Entry: "email/gmail (myusername)"
59114
>>> kp.save()
60115
```
61116

62-
Finding and manipulating entries
117+
## Finding and Manipulating Entries
63118

64119
``` python
65120
# add a new entry to the Root group
@@ -94,7 +149,7 @@ Entry: "testing (foo_user)"
94149
>>> entry.save_history()
95150
```
96151

97-
Finding and manipulating groups
152+
## Finding and Manipulating Groups
98153

99154
``` python
100155
>>> kp.groups
@@ -142,7 +197,7 @@ Group: "social/gmail"
142197
>>> group.touch(modify=True)
143198
```
144199

145-
Attachments
200+
## Attachments
146201

147202
``` python
148203
>>> e = kp.add_entry(kp.root_group, title='foo', username='', password='')
@@ -176,16 +231,16 @@ b'Hello world'
176231

177232
# search attachments
178233
>>> kp.find_attachments(filename='hello.txt')
179-
[Attachment: 'hello.txt** -> 0]
234+
[Attachment: 'hello.txt' -> 0]
180235

181236
# delete attachment reference
182237
>>> e.delete_attachment(a)
183238

184239
# or, delete both attachment reference and binary
185-
>>> kp.delete_binary(binary_id**
240+
>>> kp.delete_binary(binary_id)
186241
```
187242

188-
OTP codes
243+
## OTP Codes
189244

190245
``` python
191246
# find an entry which has otp attribute
@@ -195,10 +250,35 @@ OTP codes
195250
799270
196251
```
197252

253+
## Modifying KDF Parameters
254+
255+
You can adjust key derivation function parameters on an existing database:
256+
257+
``` python
258+
# KDBX4: Argon2 parameters
259+
>>> kp.argon2_iterations = 10
260+
>>> kp.argon2_memory = 131072 # in KB
261+
>>> kp.argon2_parallelism = 4
262+
>>> kp.argon2_variant = 'id' # 'id', 'd', or 'i'
263+
264+
# KDBX3: AES-KDF rounds
265+
>>> kp.transform_rounds = 100000
266+
267+
# changes take effect on next save()
268+
>>> kp.save()
269+
```
270+
271+
Note: Changing KDF parameters requires re-encrypting the database with the new settings.
272+
198273

199274
# Tests and Debugging
200275

201-
Run tests with `python tests/tests.py` or `python tests/tests.py SomeSpecificTest`
276+
Run tests with pytest:
277+
278+
``` bash
279+
pytest tests/ -v
280+
pytest tests/ -v -k 'SomeSpecificTest'
281+
```
202282

203283
Enable debugging when doing tests in console:
204284

0 commit comments

Comments
 (0)