Coverage for src / kdbxtool / __init__.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-01-20 19:19 +0000

1"""kdbxtool - A modern, secure Python library for KeePass KDBX databases. 

2 

3This library provides a clean, type-safe API for reading and writing KeePass 

4database files (KDBX format). It prioritizes security with: 

5- Secure memory handling (zeroization of sensitive data) 

6- Constant-time comparisons for authentication 

7- Modern cryptographic defaults (Argon2d, ChaCha20) 

8 

9Example: 

10 from kdbxtool import Database 

11 

12 db = Database.open("vault.kdbx", password="secret") 

13 entry = db.find_entries(title="Gmail")[0] 

14 print(entry.username) 

15 

16 # Create new entry 

17 db.root_group.create_entry( 

18 title="New Site", 

19 username="user", 

20 password="pass123", 

21 ) 

22 db.save() 

23""" 

24 

25import logging 

26from importlib.metadata import version 

27 

28from .database import Database, DatabaseSettings 

29from .exceptions import ( 

30 AuthenticationError, 

31 CorruptedDataError, 

32 CredentialError, 

33 CryptoError, 

34 DatabaseError, 

35 DecryptionError, 

36 EntryNotFoundError, 

37 FormatError, 

38 GroupNotFoundError, 

39 InvalidKeyFileError, 

40 InvalidPasswordError, 

41 InvalidSignatureError, 

42 InvalidXmlError, 

43 Kdbx3UpgradeRequired, 

44 KdbxError, 

45 KdfError, 

46 MergeError, 

47 MissingCredentialsError, 

48 TwofishNotAvailableError, 

49 UnknownCipherError, 

50 UnsupportedVersionError, 

51 YubiKeyError, 

52 YubiKeyNotAvailableError, 

53 YubiKeyNotFoundError, 

54 YubiKeySlotError, 

55 YubiKeyTimeoutError, 

56) 

57from .merge import DeletedObject, MergeMode, MergeResult 

58from .models import Attachment, Entry, Group, HistoryEntry, Times 

59from .security import AesKdfConfig, Argon2Config, Cipher, KdfType 

60from .security.keyfile import ( 

61 KeyFileVersion, 

62 create_keyfile, 

63 create_keyfile_bytes, 

64 parse_keyfile, 

65) 

66from .security.yubikey import ( 

67 YubiKeyConfig, 

68 check_slot_configured, 

69 list_yubikeys, 

70) 

71from .templates import EntryTemplate, IconId, Templates 

72 

73__version__ = version("kdbxtool") 

74 

75# Configure library logger to prevent "No handler found" warnings 

76# when users don't configure logging in their applications 

77logging.getLogger("kdbxtool").addHandler(logging.NullHandler()) 

78 

79__all__ = [ 

80 # Core classes 

81 "AesKdfConfig", 

82 "Argon2Config", 

83 "Attachment", 

84 "Database", 

85 "DatabaseSettings", 

86 "Entry", 

87 "Group", 

88 "HistoryEntry", 

89 "Times", 

90 "Cipher", 

91 "KdfType", 

92 # Merge support 

93 "MergeMode", 

94 "MergeResult", 

95 "DeletedObject", 

96 # Entry templates 

97 "EntryTemplate", 

98 "IconId", 

99 "Templates", 

100 # Keyfile support 

101 "KeyFileVersion", 

102 "create_keyfile", 

103 "create_keyfile_bytes", 

104 "parse_keyfile", 

105 # YubiKey support 

106 "YubiKeyConfig", 

107 "check_slot_configured", 

108 "list_yubikeys", 

109 # Exceptions 

110 "KdbxError", 

111 "FormatError", 

112 "InvalidSignatureError", 

113 "UnsupportedVersionError", 

114 "CorruptedDataError", 

115 "CryptoError", 

116 "DecryptionError", 

117 "AuthenticationError", 

118 "KdfError", 

119 "TwofishNotAvailableError", 

120 "UnknownCipherError", 

121 "CredentialError", 

122 "InvalidPasswordError", 

123 "InvalidKeyFileError", 

124 "MergeError", 

125 "MissingCredentialsError", 

126 "DatabaseError", 

127 "EntryNotFoundError", 

128 "GroupNotFoundError", 

129 "InvalidXmlError", 

130 "Kdbx3UpgradeRequired", 

131 "YubiKeyError", 

132 "YubiKeyNotAvailableError", 

133 "YubiKeyNotFoundError", 

134 "YubiKeySlotError", 

135 "YubiKeyTimeoutError", 

136]