Column


Matching strategies at a glance

Pattern type

Behaviour

str

Exact match (or case-insensitive with ignore_case=True)

str + regexp=True

Compiled to re.Pattern, matched with re.search()

re.Pattern

Matched with re.search(); ignore_case is ignored

Callable[[str], bool]

Called with each header cell; first True wins

Examples

import re
from xlea import Schema, Column

class Invoice(Schema):
    # Exact match
    invoice_id: int = Column("Invoice ID")

    # Case-insensitive
    client: str = Column("client name", ignore_case=True)

    # Regex from string
    ref: str = Column(r"^Ref\s*#?\s*\d*$", regexp=True)

    # Compiled regex
    amount: float = Column(re.compile(r"amount", re.IGNORECASE))

    # Callable predicate
    note: str = Column(
        lambda h: h.lower().startswith("note"),
        required=False,
        default="",
    )