Skip to content

Conversation

@coreyleavitt
Copy link
Owner

@coreyleavitt coreyleavitt commented Dec 11, 2025

Summary

Implements typed template classes for entry creation with full IDE autocompletion and type safety.

Key changes:

  • EntryTemplate base class for custom templates (subclass to create your own)
  • Built-in templates via Templates namespace: Login, CreditCard, SecureNote, Identity, BankAccount, Server, WirelessRouter, Email, SoftwareLicense, Database
  • IconId enum with all 69 KeePass standard icons (PwIcon 0-68)
  • Templates carry their field values as typed dataclass fields
  • Protected fields via _protected_fields ClassVar
  • _include_standard flag controls whether username/password/url are populated

Usage

from kdbxtool import Database, Templates

db = Database.create(password="secret")

# Built-in template with IDE completion
entry = db.root_group.create_entry(
    title="My Visa",
    template=Templates.CreditCard(
        card_number="4111111111111111",
        expiry_date="12/25",
        cvv="123",
    ),
)

# Custom template
from dataclasses import dataclass
from typing import ClassVar
from kdbxtool import EntryTemplate, IconId

@dataclass
class VPNConnection(EntryTemplate):
    _icon_id: ClassVar[int] = IconId.TERMINAL_ENCRYPTED
    _protected_fields: ClassVar[frozenset[str]] = frozenset({"certificate"})

    server: str | None = None
    protocol: str = "OpenVPN"
    certificate: str | None = None

entry = db.root_group.create_entry(
    title="Work VPN",
    template=VPNConnection(server="vpn.company.com"),
)

Test plan

  • 26 template tests covering all built-in templates and custom templates
  • All 702 existing tests pass
  • mypy --strict passes
  • ruff check passes

Closes #58

@coreyleavitt coreyleavitt force-pushed the feature/entry-templates branch from 1b9906a to 2b38617 Compare December 11, 2025 22:16
Implements typed template classes for entry creation with full IDE support.

Features:
- EntryTemplate base class for custom templates
- Built-in templates: Login, CreditCard, SecureNote, Identity, BankAccount,
  Server, WirelessRouter, Email, SoftwareLicense, DatabaseConnection
- Templates namespace for discoverability (Templates.CreditCard, etc.)
- IconId enum with all 69 KeePass standard icons (PwIcon 0-68)
- _protected_fields ClassVar for memory-protected fields
- _include_standard ClassVar to control standard field population
- _get_fields() method extracts typed field values

Usage:
    from kdbxtool import Database, Templates

    entry = group.create_entry(
        title="My Card",
        template=Templates.CreditCard(
            card_number="4111111111111111",
            cvv="123",
        ),
    )

Custom templates via subclassing:
    @DataClass
    class VPNConnection(EntryTemplate):
        _icon_id: ClassVar[int] = IconId.TERMINAL_ENCRYPTED
        _protected_fields: ClassVar[frozenset[str]] = frozenset({"certificate"})

        server: str | None = None
        certificate: str | None = None

Also adds ruff per-file-ignores for S101/S105/S106 in tests.

Closes #58
@coreyleavitt coreyleavitt force-pushed the feature/entry-templates branch from 2b38617 to ea37c1c Compare December 11, 2025 23:12
@coreyleavitt coreyleavitt merged commit c7af4eb into master Dec 12, 2025
6 checks passed
@coreyleavitt coreyleavitt deleted the feature/entry-templates branch December 12, 2025 01:06
coreyleavitt added a commit that referenced this pull request Dec 14, 2025
Implements typed template classes for entry creation with full IDE support.

Features:
- EntryTemplate base class for custom templates
- Built-in templates: Login, CreditCard, SecureNote, Identity, BankAccount,
  Server, WirelessRouter, Email, SoftwareLicense, DatabaseConnection
- Templates namespace for discoverability (Templates.CreditCard, etc.)
- IconId enum with all 69 KeePass standard icons (PwIcon 0-68)
- _protected_fields ClassVar for memory-protected fields
- _include_standard ClassVar to control standard field population
- _get_fields() method extracts typed field values

Usage:
    from kdbxtool import Database, Templates

    entry = group.create_entry(
        title="My Card",
        template=Templates.CreditCard(
            card_number="4111111111111111",
            cvv="123",
        ),
    )

Custom templates via subclassing:
    @DataClass
    class VPNConnection(EntryTemplate):
        _icon_id: ClassVar[int] = IconId.TERMINAL_ENCRYPTED
        _protected_fields: ClassVar[frozenset[str]] = frozenset({"certificate"})

        server: str | None = None
        certificate: str | None = None

Also adds ruff per-file-ignores for S101/S105/S106 in tests.

Closes #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add entry templates for common account types

2 participants