Skip to content

API reference

The importable Python surface: the loading and summary functions, the Camt054NotificationSummary dataclass, and Camt054StatementParser, the BankStatementParser the core discovers through the camt054 and camt_054 entry points in bankstatementparser.loaders. Generated from the docstrings by mkdocstrings.

bankstatementparser_loader_camt054.loader

Core ISO 20022 CAMT.054 Debit/Credit Notification Loader.

Camt054NotificationSummary dataclass

Summary metrics and headers for a CAMT.054 notification message.

Source code in bankstatementparser_loader_camt054/loader.py
36
37
38
39
40
41
42
43
44
45
46
47
@dataclass(frozen=True)
class Camt054NotificationSummary:
    """Summary metrics and headers for a CAMT.054 notification message."""

    message_id: str | None
    creation_date: datetime | None
    account_id: str | None
    currency: str | None
    notification_count: int
    entry_count: int
    total_credit: Decimal
    total_debit: Decimal

Camt054StatementParser

Bases: BankStatementParser

BankStatementParser plugin implementation for ISO 20022 CAMT.054 XML files.

Source code in bankstatementparser_loader_camt054/loader.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
class Camt054StatementParser(BankStatementParser):
    """BankStatementParser plugin implementation for ISO 20022 CAMT.054 XML files."""

    def __init__(self, file_name: str | Path, **kwargs: Any) -> None:
        """Initialize the CAMT.054 statement parser.

        Args:
            file_name: Path to the CAMT.054 XML file.
            **kwargs: Extra options passed to the base parser.
        """
        super().__init__(file_name, **kwargs)
        self._summary_cache: Camt054NotificationSummary | None = None

    def parse(self) -> pd.DataFrame:
        """Parse the CAMT.054 XML file into a pandas DataFrame.

        Returns:
            A pandas DataFrame containing standardized statement transactions.
        """
        txs = self.to_transactions()
        if not txs:
            return pd.DataFrame(
                columns=[
                    "date",
                    "description",
                    "amount",
                    "currency",
                    "account_id",
                    "reference",
                    "source",
                ]
            )

        records = [
            {
                "date": tx.booking_date.isoformat() if tx.booking_date else "",
                "description": tx.description or "",
                "amount": float(tx.amount),
                "currency": tx.currency,
                "account_id": tx.account_id,
                "reference": tx.reference,
                "source": tx.source,
            }
            for tx in txs
        ]
        return pd.DataFrame(records)

    def to_transactions(self) -> list[Transaction]:
        """Parse the CAMT.054 XML file into a list of Transaction models.

        Returns:
            List of parsed Transaction instances.
        """
        return load_camt054_file(self.file_name)

    def get_summary(self) -> Camt054SummaryRecord:
        """Get summary metadata and balance metrics for the CAMT.054 notification file.

        Returns:
            Dictionary with statement statistics.
        """
        if self._summary_cache is None:
            content = Path(self.file_name).read_bytes()
            self._summary_cache = summarize_camt054(content)

        s = self._summary_cache
        return {
            "message_id": s.message_id,
            "account_id": s.account_id,
            "currency": s.currency,
            "creation_date": (
                s.creation_date.isoformat() if s.creation_date else None
            ),
            "notification_count": s.notification_count,
            "entry_count": s.entry_count,
            "total_credit": float(s.total_credit),
            "total_debit": float(s.total_debit),
        }

__init__(file_name, **kwargs)

Initialize the CAMT.054 statement parser.

Parameters:

Name Type Description Default
file_name str | Path

Path to the CAMT.054 XML file.

required
**kwargs Any

Extra options passed to the base parser.

{}
Source code in bankstatementparser_loader_camt054/loader.py
357
358
359
360
361
362
363
364
365
def __init__(self, file_name: str | Path, **kwargs: Any) -> None:
    """Initialize the CAMT.054 statement parser.

    Args:
        file_name: Path to the CAMT.054 XML file.
        **kwargs: Extra options passed to the base parser.
    """
    super().__init__(file_name, **kwargs)
    self._summary_cache: Camt054NotificationSummary | None = None

parse()

Parse the CAMT.054 XML file into a pandas DataFrame.

Returns:

Type Description
DataFrame

A pandas DataFrame containing standardized statement transactions.

Source code in bankstatementparser_loader_camt054/loader.py
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
def parse(self) -> pd.DataFrame:
    """Parse the CAMT.054 XML file into a pandas DataFrame.

    Returns:
        A pandas DataFrame containing standardized statement transactions.
    """
    txs = self.to_transactions()
    if not txs:
        return pd.DataFrame(
            columns=[
                "date",
                "description",
                "amount",
                "currency",
                "account_id",
                "reference",
                "source",
            ]
        )

    records = [
        {
            "date": tx.booking_date.isoformat() if tx.booking_date else "",
            "description": tx.description or "",
            "amount": float(tx.amount),
            "currency": tx.currency,
            "account_id": tx.account_id,
            "reference": tx.reference,
            "source": tx.source,
        }
        for tx in txs
    ]
    return pd.DataFrame(records)

to_transactions()

Parse the CAMT.054 XML file into a list of Transaction models.

Returns:

Type Description
list[Transaction]

List of parsed Transaction instances.

Source code in bankstatementparser_loader_camt054/loader.py
401
402
403
404
405
406
407
def to_transactions(self) -> list[Transaction]:
    """Parse the CAMT.054 XML file into a list of Transaction models.

    Returns:
        List of parsed Transaction instances.
    """
    return load_camt054_file(self.file_name)

get_summary()

Get summary metadata and balance metrics for the CAMT.054 notification file.

Returns:

Type Description
Camt054SummaryRecord

Dictionary with statement statistics.

Source code in bankstatementparser_loader_camt054/loader.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
def get_summary(self) -> Camt054SummaryRecord:
    """Get summary metadata and balance metrics for the CAMT.054 notification file.

    Returns:
        Dictionary with statement statistics.
    """
    if self._summary_cache is None:
        content = Path(self.file_name).read_bytes()
        self._summary_cache = summarize_camt054(content)

    s = self._summary_cache
    return {
        "message_id": s.message_id,
        "account_id": s.account_id,
        "currency": s.currency,
        "creation_date": (
            s.creation_date.isoformat() if s.creation_date else None
        ),
        "notification_count": s.notification_count,
        "entry_count": s.entry_count,
        "total_credit": float(s.total_credit),
        "total_debit": float(s.total_debit),
    }

load_camt054(xml_content)

Parse an ISO 20022 CAMT.054 XML notification payload into Transaction objects.

Parameters:

Name Type Description Default
xml_content str | bytes

XML string or raw bytes.

required

Returns:

Type Description
list[Transaction]

List of Transaction instances.

Source code in bankstatementparser_loader_camt054/loader.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def load_camt054(xml_content: str | bytes) -> list[Transaction]:
    """Parse an ISO 20022 CAMT.054 XML notification payload into Transaction objects.

    Args:
        xml_content: XML string or raw bytes.

    Returns:
        List of Transaction instances.
    """
    _, records = _parse_camt054_xml(xml_content)
    transactions: list[Transaction] = []

    for idx, rec in enumerate(records):
        tx = Transaction(
            account_id=rec.get("account_id"),
            currency=rec.get("currency"),
            amount=rec["amount"],
            booking_date=rec.get("booking_date"),
            value_date=rec.get("value_date"),
            description=rec.get("description") or None,
            reference=rec.get("reference"),
            category=rec.get("category"),
            source=SOURCE,
            source_index=idx,
        )
        transactions.append(tx)

    return transactions

load_camt054_file(path)

Read and parse a CAMT.054 XML file from disk.

Parameters:

Name Type Description Default
path str | PathLike[str]

Filesystem path to the XML file.

required

Returns:

Type Description
list[Transaction]

List of Transaction instances.

Source code in bankstatementparser_loader_camt054/loader.py
305
306
307
308
309
310
311
312
313
314
315
def load_camt054_file(path: str | os.PathLike[str]) -> list[Transaction]:
    """Read and parse a CAMT.054 XML file from disk.

    Args:
        path: Filesystem path to the XML file.

    Returns:
        List of Transaction instances.
    """
    data = Path(path).read_bytes()
    return load_camt054(data)

summarize_camt054(xml_content)

Generate a financial summary of a CAMT.054 notification document.

Parameters:

Name Type Description Default
xml_content str | bytes

XML string or raw bytes.

required

Returns:

Type Description
Camt054NotificationSummary

A Camt054NotificationSummary instance.

Source code in bankstatementparser_loader_camt054/loader.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def summarize_camt054(xml_content: str | bytes) -> Camt054NotificationSummary:
    """Generate a financial summary of a CAMT.054 notification document.

    Args:
        xml_content: XML string or raw bytes.

    Returns:
        A Camt054NotificationSummary instance.
    """
    header, records = _parse_camt054_xml(xml_content)

    total_credit = Decimal("0.00")
    total_debit = Decimal("0.00")
    first_curr = None

    for rec in records:
        amt = rec["amount"]
        if not first_curr and rec.get("currency"):
            first_curr = rec["currency"]
        if amt > 0:
            total_credit += amt
        else:
            total_debit += abs(amt)

    return Camt054NotificationSummary(
        message_id=header.get("message_id"),
        creation_date=header.get("creation_date"),
        account_id=header.get("account_id"),
        currency=header.get("currency") or first_curr,
        notification_count=header.get("notification_count", 0),
        entry_count=len(records),
        total_credit=total_credit,
        total_debit=total_debit,
    )