kdbxtool.models.entry¶
Entry model for KDBX password entries.
Classes
|
AutoType settings for an entry. |
|
Reference to a binary attachment. |
|
A password entry in a KDBX database. |
|
A historical version of an entry. |
|
A string field in an entry. |
- class kdbxtool.models.entry.StringField(key, value=None, protected=False)[source]¶
Bases:
objectA string field in an entry.
- class kdbxtool.models.entry.AutoType(enabled=True, sequence=None, window=None, obfuscation=0)[source]¶
Bases:
objectAutoType settings for an entry.
- class kdbxtool.models.entry.BinaryRef(key, ref)[source]¶
Bases:
objectReference to a binary attachment.
- class kdbxtool.models.entry.Entry(uuid=<factory>, times=<factory>, icon_id='0', custom_icon_uuid=None, tags=<factory>, strings=<factory>, binaries=<factory>, autotype=<factory>, history=<factory>, foreground_color=None, background_color=None, override_url=None, quality_check=True, _parent=None, _database=None)[source]¶
Bases:
objectA password entry in a KDBX database.
Entries store credentials and associated metadata. Each entry has standard fields (title, username, password, url, notes) plus support for custom string fields and binary attachments.
- Parameters:
uuid (uuid_module.UUID)
times (Times)
icon_id (str)
custom_icon_uuid (uuid_module.UUID | None)
strings (dict[str, StringField])
autotype (AutoType)
history (list[HistoryEntry])
foreground_color (str | None)
background_color (str | None)
override_url (str | None)
quality_check (bool)
_parent (Group | None)
_database (Database | None)
- uuid¶
Unique identifier for the entry
- Type:
uuid_module.UUID
- custom_icon_uuid¶
UUID of custom icon (overrides icon_id if set)
- Type:
uuid_module.UUID | None
- strings¶
Dictionary of string fields (key -> StringField)
- Type:
- history¶
List of previous versions of this entry
- Type:
- uuid: uuid_module.UUID¶
- strings: dict[str, StringField]¶
- history: list[HistoryEntry]¶
- totp(*, at=None)[source]¶
Generate current TOTP code from the entry’s otp field.
Supports both standard otpauth:// URIs and KeePassXC legacy format (TOTP Seed / TOTP Settings custom fields).
- Parameters:
at (datetime | float | None) – Optional timestamp for code generation. Can be a datetime or Unix timestamp float. Defaults to current time.
- Returns:
TotpCode object with code and expiration info, or None if no OTP configured.
- Raises:
ValueError – If OTP configuration is invalid
- Return type:
TotpCode | None
Example
>>> result = entry.totp() >>> print(f"Code: {result.code}") Code: 123456
>>> print(f"Expires in {result.remaining}s") Expires in 15s
>>> # TotpCode also works as a string >>> print(result) 123456
- property custom_icon: UUID | None¶
Get or set custom icon by UUID or name.
When setting, accepts either a UUID or an icon name (string). If a string is provided, it must match exactly one icon name in the database. Requires the entry to be associated with a database for name-based lookup.
- Returns:
UUID of the custom icon, or None if not set
- get_custom_property(key)[source]¶
Get a custom property value.
- Parameters:
key (str) – Property name (must not be a reserved key)
- Returns:
Property value, or None if not set
- Raises:
ValueError – If key is a reserved key
- Return type:
str | None
- set_custom_property(key, value, protected=False)[source]¶
Set a custom property.
- Parameters:
- Raises:
ValueError – If key is a reserved key
- Return type:
None
- delete_custom_property(key)[source]¶
Delete a custom property.
- Parameters:
key (str) – Property name to delete
- Raises:
ValueError – If key is a reserved key
KeyError – If property doesn’t exist
- Return type:
None
- property index: int¶
Get the index of this entry within its parent group.
- Returns:
Zero-based index of this entry in the parent’s entries list.
- Raises:
ValueError – If entry has no parent group.
- touch(modify=False)[source]¶
Update access time, optionally modification time.
- Parameters:
modify (bool)
- Return type:
None
- reindex(new_index)[source]¶
Move this entry to a new position within its parent group.
- Parameters:
new_index (int) – Target position (zero-based). Negative indices are supported (e.g., -1 for last position).
- Raises:
ValueError – If entry has no parent group.
IndexError – If new_index is out of range.
- Return type:
None
- delete_history(history_entry=None, *, all=False)[source]¶
Delete history entries.
Either deletes a specific history entry or all history entries. At least one of history_entry or all=True must be specified.
- Parameters:
history_entry (HistoryEntry | None) – Specific history entry to delete
all (bool) – If True, delete all history entries
- Raises:
ValueError – If neither history_entry nor all=True is specified
ValueError – If history_entry is not in this entry’s history
- Return type:
None
- clear_history()[source]¶
Clear all history entries.
This is a convenience method equivalent to delete_history(all=True).
- Return type:
None
- move_to(destination)[source]¶
Move this entry to a different group.
Removes the entry from its current parent and adds it to the destination group. Updates the location_changed timestamp.
- Parameters:
destination (Group) – Target group to move the entry to
- Raises:
ValueError – If entry has no parent (not yet added to a group)
ValueError – If destination is the current parent (no-op would be confusing)
- Return type:
None
- ref(field)[source]¶
Create a reference string pointing to a field of this entry.
Creates a KeePass field reference string that can be used in other entries to reference values from this entry. References use the entry’s UUID for lookup.
- Parameters:
field (str) – One of ‘title’, ‘username’, ‘password’, ‘url’, ‘notes’, or ‘uuid’
- Returns:
X@I:UUID}
- Return type:
Field reference string in format {REF
- Raises:
ValueError – If field is not a valid field name
Example
>>> main_entry = db.find_entries(title='Main Account', first=True) >>> ref_string = main_entry.ref('password') >>> # Returns '{REF:P@I:...UUID...}' >>> other_entry.password = ref_string
- deref(field)[source]¶
Resolve any field references in the given field’s value.
If the field’s value contains KeePass field references ({REF:X@Y:Z}), resolves them to the actual values from the referenced entries.
- Parameters:
field (str) – One of ‘title’, ‘username’, ‘password’, ‘url’, ‘notes’
- Returns:
The resolved value with all references replaced, a UUID if the referenced field is ‘uuid’, or None if a referenced entry is not found
- Raises:
ValueError – If no database reference is available
- Return type:
Example
>>> # If entry.password contains '{REF:P@I:...UUID...}' >>> actual_password = entry.deref('password')
- dump()[source]¶
Return a human-readable summary of the entry for debugging.
- Returns:
Multi-line string with entry details (passwords are masked).
- Return type:
- __init__(uuid=<factory>, times=<factory>, icon_id='0', custom_icon_uuid=None, tags=<factory>, strings=<factory>, binaries=<factory>, autotype=<factory>, history=<factory>, foreground_color=None, background_color=None, override_url=None, quality_check=True, _parent=None, _database=None)¶
- Parameters:
uuid (uuid_module.UUID)
times (Times)
icon_id (str)
custom_icon_uuid (uuid_module.UUID | None)
strings (dict[str, StringField])
autotype (AutoType)
history (list[HistoryEntry])
foreground_color (str | None)
background_color (str | None)
override_url (str | None)
quality_check (bool)
_parent (Group | None)
_database (Database | None)
- Return type:
None
- class kdbxtool.models.entry.HistoryEntry(uuid=<factory>, times=<factory>, icon_id='0', custom_icon_uuid=None, tags=<factory>, strings=<factory>, binaries=<factory>, autotype=<factory>, history=<factory>, foreground_color=None, background_color=None, override_url=None, quality_check=True, _parent=None, _database=None)[source]¶
Bases:
EntryA historical version of an entry.
History entries are snapshots of an entry at a previous point in time. They share the same UUID as their parent entry.
- Parameters:
uuid (uuid_module.UUID)
times (Times)
icon_id (str)
custom_icon_uuid (uuid_module.UUID | None)
strings (dict[str, StringField])
autotype (AutoType)
history (list[HistoryEntry])
foreground_color (str | None)
background_color (str | None)
override_url (str | None)
quality_check (bool)
_parent (Group | None)
_database (Database | None)
- __init__(uuid=<factory>, times=<factory>, icon_id='0', custom_icon_uuid=None, tags=<factory>, strings=<factory>, binaries=<factory>, autotype=<factory>, history=<factory>, foreground_color=None, background_color=None, override_url=None, quality_check=True, _parent=None, _database=None)¶
- Parameters:
uuid (uuid_module.UUID)
times (Times)
icon_id (str)
custom_icon_uuid (uuid_module.UUID | None)
strings (dict[str, StringField])
autotype (AutoType)
history (list[HistoryEntry])
foreground_color (str | None)
background_color (str | None)
override_url (str | None)
quality_check (bool)
_parent (Group | None)
_database (Database | None)
- Return type:
None