bankstatementparser 0.0.22__tar.gz → 0.0.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/PKG-INFO +6 -4
  2. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/README.md +3 -2
  3. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/__init__.py +1 -1
  4. bankstatementparser-0.0.24/bankstatementparser/additional_parsers.py +150 -0
  5. bankstatementparser-0.0.24/bankstatementparser/field86_parser.py +204 -0
  6. bankstatementparser-0.0.24/bankstatementparser/parsers/__init__.py +49 -0
  7. bankstatementparser-0.0.24/bankstatementparser/parsers/common.py +233 -0
  8. bankstatementparser-0.0.24/bankstatementparser/parsers/csv_parser.py +141 -0
  9. bankstatementparser-0.0.24/bankstatementparser/parsers/mt940.py +268 -0
  10. bankstatementparser-0.0.24/bankstatementparser/parsers/ofx.py +115 -0
  11. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/pyproject.toml +24 -2
  12. bankstatementparser-0.0.22/bankstatementparser/additional_parsers.py +0 -632
  13. bankstatementparser-0.0.22/bankstatementparser/field86_parser.py +0 -186
  14. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/LICENSE +0 -0
  15. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/LICENSE-APACHE +0 -0
  16. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/LICENSE-MIT +0 -0
  17. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/_amounts.py +0 -0
  18. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/_llm_common.py +0 -0
  19. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/analytics.py +0 -0
  20. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/api.py +0 -0
  21. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/bank_statement_parsers.py +0 -0
  22. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/base_parser.py +0 -0
  23. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/camt_parser.py +0 -0
  24. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/cli.py +0 -0
  25. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/enrichment/__init__.py +0 -0
  26. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/enrichment/account_mapper.py +0 -0
  27. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/enrichment/categorizer.py +0 -0
  28. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/exceptions.py +0 -0
  29. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/export/__init__.py +0 -0
  30. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/export/ledger.py +0 -0
  31. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/export/parquet.py +0 -0
  32. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/forensics.py +0 -0
  33. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/__init__.py +0 -0
  34. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/evaluation.py +0 -0
  35. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/llm_extractor.py +0 -0
  36. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/ollama_direct.py +0 -0
  37. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/orchestrator.py +0 -0
  38. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/pdf_text.py +0 -0
  39. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/prompts.py +0 -0
  40. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/scanner.py +0 -0
  41. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/verification.py +0 -0
  42. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/hybrid/vision.py +0 -0
  43. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/input_validator.py +0 -0
  44. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/pain001_parser.py +0 -0
  45. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/parallel.py +0 -0
  46. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/plugins.py +0 -0
  47. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/privacy.py +0 -0
  48. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/py.typed +0 -0
  49. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/reconciliation.py +0 -0
  50. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/record_types.py +0 -0
  51. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/transaction_deduplicator.py +0 -0
  52. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/transaction_models.py +0 -0
  53. {bankstatementparser-0.0.22 → bankstatementparser-0.0.24}/bankstatementparser/zip_security.py +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bankstatementparser
3
- Version: 0.0.22
4
- Summary: BankStatementParser is your essential tool for easy bank statement management. Designed with finance and treasury experts in mind, it offers a simple way to handle CAMT (ISO 20022) formats and more. Get quick, accurate insights from your financial data and spend less time on processing. It's the smart, hassle-free way to stay on top of your transactions.
3
+ Version: 0.0.24
4
+ Summary: Parse bank statements (CAMT.053, PAIN.001, MT940, OFX, BAI2, CSV, and PDF) into unified Transactions with treasury analytics, 2-way reconciliation, PDF forensics, and ledger export.
5
5
  License: Apache-2.0 OR MIT
6
6
  License-File: LICENSE
7
7
  License-File: LICENSE-APACHE
8
8
  License-File: LICENSE-MIT
9
+ Keywords: banking,finance,iso20022,camt053,pain001,mt940,ofx,bai2,sepa,fintech,treasury,python,reconciliation,hledger,beancount,parquet,pdf-parsing,fastapi,cli,bank-statements
9
10
  Author: Sebastien Rousseau
10
11
  Author-email: sebastian.rousseau@gmail.com
11
12
  Requires-Python: >=3.10,<4.0
@@ -63,7 +64,7 @@ Description-Content-Type: text/markdown
63
64
 
64
65
  <p align="center">
65
66
  <a href="https://github.com/sebastienrousseau/bankstatementparser/actions"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/bankstatementparser/quality-gates.yml?style=for-the-badge&logo=github" alt="Build" /></a>
66
- <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/pyversions/bankstatementparser.svg?style=for-the-badge&v=0.0.22" alt="PyPI" /></a>
67
+ <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/pyversions/bankstatementparser.svg?style=for-the-badge&v=0.0.24" alt="PyPI" /></a>
67
68
  <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/dm/bankstatementparser.svg?style=for-the-badge" alt="PyPI Downloads" /></a>
68
69
  <a href="https://codecov.io/github/sebastienrousseau/bankstatementparser?branch=main"><img src="https://img.shields.io/codecov/c/github/sebastienrousseau/bankstatementparser?style=for-the-badge" alt="Codecov" /></a>
69
70
  <a href="LICENSE"><img src="https://img.shields.io/github/license/sebastienrousseau/bankstatementparser?style=for-the-badge" alt="License" /></a>
@@ -749,7 +750,8 @@ cleanly — see each companion's README for runnable examples.
749
750
  ## Project Layout
750
751
 
751
752
  ```text
752
- bankstatementparser/ Source code (39 modules)
753
+ bankstatementparser/ Source code (44 modules)
754
+ bankstatementparser/parsers/ Modular statement parsers (CSV, MT940, OFX/QFX)
753
755
  bankstatementparser/hybrid/ PDF pipeline: orchestrator, llm_extractor, vision, scanner, ollama_direct, verification
754
756
  bankstatementparser/enrichment/ Categorizer, AccountMapper, EnrichedTransaction
755
757
  bankstatementparser/export/ hledger + beancount journal export, Apache Parquet columnar export
@@ -19,7 +19,7 @@
19
19
 
20
20
  <p align="center">
21
21
  <a href="https://github.com/sebastienrousseau/bankstatementparser/actions"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/bankstatementparser/quality-gates.yml?style=for-the-badge&logo=github" alt="Build" /></a>
22
- <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/pyversions/bankstatementparser.svg?style=for-the-badge&v=0.0.22" alt="PyPI" /></a>
22
+ <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/pyversions/bankstatementparser.svg?style=for-the-badge&v=0.0.24" alt="PyPI" /></a>
23
23
  <a href="https://pypi.org/project/bankstatementparser/"><img src="https://img.shields.io/pypi/dm/bankstatementparser.svg?style=for-the-badge" alt="PyPI Downloads" /></a>
24
24
  <a href="https://codecov.io/github/sebastienrousseau/bankstatementparser?branch=main"><img src="https://img.shields.io/codecov/c/github/sebastienrousseau/bankstatementparser?style=for-the-badge" alt="Codecov" /></a>
25
25
  <a href="LICENSE"><img src="https://img.shields.io/github/license/sebastienrousseau/bankstatementparser?style=for-the-badge" alt="License" /></a>
@@ -705,7 +705,8 @@ cleanly — see each companion's README for runnable examples.
705
705
  ## Project Layout
706
706
 
707
707
  ```text
708
- bankstatementparser/ Source code (39 modules)
708
+ bankstatementparser/ Source code (44 modules)
709
+ bankstatementparser/parsers/ Modular statement parsers (CSV, MT940, OFX/QFX)
709
710
  bankstatementparser/hybrid/ PDF pipeline: orchestrator, llm_extractor, vision, scanner, ollama_direct, verification
710
711
  bankstatementparser/enrichment/ Categorizer, AccountMapper, EnrichedTransaction
711
712
  bankstatementparser/export/ hledger + beancount journal export, Apache Parquet columnar export
@@ -91,7 +91,7 @@ from .zip_security import (
91
91
  #: so the conformance gate can compare it statically against
92
92
  #: pyproject.toml -- that comparison is the thing that catches drift, and
93
93
  #: a runtime lookup would make the two trivially equal and check nothing.
94
- __version__ = "0.0.22"
94
+ __version__ = "0.0.24"
95
95
 
96
96
  __all__ = [
97
97
  "AnalyticsReport",
@@ -0,0 +1,150 @@
1
+ # Copyright (C) 2023-2026 Bank Statement Parser. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
+ # implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Additional bank statement parsers and format detection helpers."""
17
+
18
+ from __future__ import annotations
19
+
20
+ from pathlib import Path
21
+
22
+ from .base_parser import BankStatementParser
23
+ from .camt_parser import CamtParser
24
+ from .input_validator import ValidationError
25
+ from .pain001_parser import Pain001Parser
26
+ from .parsers import (
27
+ CSV_COLUMN_GROUPS,
28
+ CsvStatementParser,
29
+ Mt940Parser,
30
+ OfxParser,
31
+ QfxParser,
32
+ _amount_or_zero,
33
+ _grouped_summaries,
34
+ _normalize_delimiters,
35
+ _normalized_name,
36
+ _parse_amount,
37
+ _read_validated_text,
38
+ _require_amount,
39
+ _summary_text,
40
+ )
41
+ from .plugins import get_registered_loaders
42
+
43
+ __all__ = [
44
+ "CSV_COLUMN_GROUPS",
45
+ "CsvStatementParser",
46
+ "Mt940Parser",
47
+ "OfxParser",
48
+ "QfxParser",
49
+ "_amount_or_zero",
50
+ "_grouped_summaries",
51
+ "_normalize_delimiters",
52
+ "_normalized_name",
53
+ "_parse_amount",
54
+ "_read_validated_text",
55
+ "_require_amount",
56
+ "_summary_text",
57
+ "create_parser",
58
+ "detect_statement_format",
59
+ ]
60
+
61
+
62
+ def _detect_by_suffix(suffix: str) -> str | None:
63
+ """Detect statement format from file extension."""
64
+ if suffix == ".csv":
65
+ return "csv"
66
+ if suffix in {".ofx", ".qfx"}:
67
+ return "ofx"
68
+ if suffix in {".mt940", ".sta"}:
69
+ return "mt940"
70
+ if suffix == ".bai2":
71
+ return "bai2"
72
+ if suffix == ".mt942":
73
+ return "mt942"
74
+ return None
75
+
76
+
77
+ def _detect_xml_format(lowered: str) -> str | None:
78
+ """Detect statement format from XML content tags."""
79
+ if "cstmrcdttrfinitn" in lowered or "pain.001" in lowered:
80
+ return "pain001"
81
+ if "bktocstmrstmt" in lowered or "camt." in lowered:
82
+ return "camt"
83
+ return None
84
+
85
+
86
+ def _detect_by_content(text: str, lowered: str) -> str | None:
87
+ """Detect statement format from file text contents."""
88
+ if text.startswith("01,") or "\n01," in text:
89
+ return "bai2"
90
+ if ":34F:" in text and ":61:" in text:
91
+ return "mt942"
92
+ if "<ofx>" in lowered or "<banktranlist>" in lowered:
93
+ return "ofx"
94
+ if ":20:" in text and ":61:" in text:
95
+ return "mt940"
96
+ return None
97
+
98
+
99
+ def _detect_by_plugin(suffix: str) -> str | None:
100
+ """Detect statement format using registered loader plugins."""
101
+ loaders = get_registered_loaders()
102
+ for name in loaders:
103
+ if suffix == f".{name}" or name in suffix:
104
+ return name
105
+ return None
106
+
107
+
108
+ def detect_statement_format(file_name: str | Path) -> str:
109
+ """Detect the parser format for a bank statement file."""
110
+ path, text = _read_validated_text(file_name)
111
+ suffix = path.suffix.lower()
112
+ lowered = text.lower()
113
+
114
+ if suffix == ".xml":
115
+ xml_fmt = _detect_xml_format(lowered)
116
+ if xml_fmt is not None:
117
+ return xml_fmt
118
+
119
+ detected = (
120
+ _detect_by_suffix(suffix)
121
+ or _detect_by_content(text, lowered)
122
+ or _detect_by_plugin(suffix)
123
+ )
124
+ if detected is not None:
125
+ return detected
126
+
127
+ raise ValidationError(f"Unable to detect statement format: {path}")
128
+
129
+
130
+ def create_parser(
131
+ file_name: str | Path,
132
+ format_name: str | None = None,
133
+ ) -> BankStatementParser:
134
+ """Create a parser instance from an explicit or detected format."""
135
+ selected = (format_name or detect_statement_format(file_name)).lower()
136
+ parser_map: dict[str, type[BankStatementParser]] = {
137
+ "camt": CamtParser,
138
+ "pain001": Pain001Parser,
139
+ "csv": CsvStatementParser,
140
+ "ofx": OfxParser,
141
+ "qfx": QfxParser,
142
+ "mt940": Mt940Parser,
143
+ }
144
+ # Augment with dynamic plugins
145
+ parser_map.update(get_registered_loaders())
146
+
147
+ if selected not in parser_map:
148
+ raise ValidationError(f"Unsupported statement format: {selected}")
149
+ parser_cls = parser_map[selected]
150
+ return parser_cls(str(file_name))
@@ -0,0 +1,204 @@
1
+ # SPDX-License-Identifier: Apache-2.0 OR MIT
2
+ # Copyright (C) 2023-2026 Bank Statement Parser. All rights reserved.
3
+
4
+ """Structured parser for SWIFT MT940/MT942 Field 86 narrative lines.
5
+
6
+ Extracts structured subfields from slash-delimited (/TAG/value) and
7
+ German SEPA GVC-delimited (?00..?63) narrative lines into a typed
8
+ Field86Structure record.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import re
14
+ from dataclasses import asdict, dataclass
15
+ from decimal import Decimal, InvalidOperation
16
+ from typing import Any
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class Field86Structure:
21
+ """Structured fields extracted from a SWIFT :86: narrative tag."""
22
+
23
+ raw_narrative: str
24
+ transaction_code: str | None = None
25
+ end_to_end_id: str | None = None
26
+ mandate_id: str | None = None
27
+ creditor_id: str | None = None
28
+ creditor_name: str | None = None
29
+ debtor_name: str | None = None
30
+ counterparty_iban: str | None = None
31
+ counterparty_bic: str | None = None
32
+ remittance_info: str | None = None
33
+ purpose_code: str | None = None
34
+ original_amount: Decimal | None = None
35
+ charges_amount: Decimal | None = None
36
+ service_reference: str | None = None
37
+ additional_tags: dict[str, str] | None = None
38
+
39
+ def to_dict(self) -> dict[str, Any]:
40
+ """Convert structured fields to a clean dictionary."""
41
+ data = asdict(self)
42
+ if self.original_amount is not None:
43
+ data["original_amount"] = str(self.original_amount)
44
+ if self.charges_amount is not None:
45
+ data["charges_amount"] = str(self.charges_amount)
46
+ return {k: v for k, v in data.items() if v is not None}
47
+
48
+
49
+ _SLASH_SUBFIELD_RE = re.compile(r"/([A-Z0-9]{2,12})/([^/]+)")
50
+ _GVC_TAG_RE = re.compile(r"\?(\d{2})([^\?]+)")
51
+ _IBAN_RE = re.compile(r"\b[A-Z]{2}\d{2}[A-Z0-9]{11,30}\b")
52
+ _BIC_RE = re.compile(r"\b[A-Z]{6}[A-Z0-9]{2}(?:[A-Z0-9]{3})?\b")
53
+ _CURRENCY_PREFIX_RE = re.compile(r"^[A-Z]{3}")
54
+
55
+ _TAG_DIRECT_MAP: dict[str, str] = {
56
+ "EREF": "end_to_end_id",
57
+ "MARF": "mandate_id",
58
+ "MREF": "mandate_id",
59
+ "CDTR": "creditor_name",
60
+ "CNAM": "creditor_name",
61
+ "CRED": "creditor_name",
62
+ "DBTR": "debtor_name",
63
+ "DNAM": "debtor_name",
64
+ "DEBT": "debtor_name",
65
+ "CDTRID": "creditor_id",
66
+ "CI": "creditor_id",
67
+ "IBAN": "counterparty_iban",
68
+ "PURP": "purpose_code",
69
+ "CODP": "purpose_code",
70
+ "SVCR": "service_reference",
71
+ "SRV": "service_reference",
72
+ }
73
+
74
+
75
+ def _parse_decimal_safe(val: str) -> Decimal | None:
76
+ """Safely convert amount string with comma or dot to Decimal."""
77
+ cleaned = val.strip().replace(",", ".").replace(" ", "")
78
+ cleaned = _CURRENCY_PREFIX_RE.sub("", cleaned)
79
+ try:
80
+ return Decimal(cleaned)
81
+ except (InvalidOperation, ValueError):
82
+ return None
83
+
84
+
85
+ def _handle_gvc_code(
86
+ code: str,
87
+ val_clean: str,
88
+ res: dict[str, Any],
89
+ remittance_parts: list[str],
90
+ creditor_parts: list[str],
91
+ ) -> None:
92
+ """Process a single GVC tag and assign to target accumulator."""
93
+ if code == "00":
94
+ res["transaction_code"] = val_clean
95
+ elif code == "10":
96
+ res["end_to_end_id"] = val_clean
97
+ elif code in ("30", "31"):
98
+ key = "counterparty_bic" if code == "30" else "counterparty_iban"
99
+ res[key] = val_clean
100
+ elif code in ("32", "33"):
101
+ creditor_parts.append(val_clean)
102
+ elif "20" <= code <= "29":
103
+ remittance_parts.append(val_clean)
104
+ else:
105
+ res["additional_tags"][f"?{code}"] = val_clean
106
+
107
+
108
+ def _parse_gvc_subfields(text: str, res: dict[str, Any]) -> None:
109
+ """Parse German SEPA GVC codes (?00..?63)."""
110
+ if "?" not in text or not _GVC_TAG_RE.search(text):
111
+ return
112
+ remittance_parts: list[str] = []
113
+ creditor_parts: list[str] = []
114
+ for code, val in _GVC_TAG_RE.findall(text):
115
+ val_clean = val.strip()
116
+ if val_clean:
117
+ _handle_gvc_code(
118
+ code, val_clean, res, remittance_parts, creditor_parts
119
+ )
120
+ if remittance_parts:
121
+ res["remittance_info"] = " ".join(remittance_parts)
122
+ if creditor_parts:
123
+ res["creditor_name"] = " ".join(creditor_parts)
124
+
125
+
126
+ def _handle_slash_tag(
127
+ tag: str,
128
+ val_clean: str,
129
+ res: dict[str, Any],
130
+ remittance_parts: list[str],
131
+ ) -> None:
132
+ """Process a single slash-delimited tag."""
133
+ if tag in ("REMI", "RMTINF"):
134
+ remittance_parts.append(val_clean)
135
+ elif tag in _TAG_DIRECT_MAP:
136
+ res[_TAG_DIRECT_MAP[tag]] = val_clean
137
+ elif tag in ("BIC", "SWIFT"):
138
+ if val_clean not in ("NOTPROVIDED", "UNDEFINED"):
139
+ res["counterparty_bic"] = val_clean
140
+ elif tag in ("OCMT", "ORAMT"):
141
+ res["original_amount"] = _parse_decimal_safe(val_clean)
142
+ elif tag in ("CHGS", "FEE"):
143
+ res["charges_amount"] = _parse_decimal_safe(val_clean)
144
+ else:
145
+ res["additional_tags"][tag] = val_clean
146
+
147
+
148
+ def _parse_slash_subfields(text: str, res: dict[str, Any]) -> None:
149
+ """Parse SWIFT standard slash-separated subfields (/TAG/value)."""
150
+ if "/" not in text:
151
+ return
152
+ remittance_parts: list[str] = []
153
+ for tag, val in _SLASH_SUBFIELD_RE.findall(text):
154
+ val_clean = val.strip()
155
+ if val_clean:
156
+ _handle_slash_tag(tag, val_clean, res, remittance_parts)
157
+ if remittance_parts and not res.get("remittance_info"):
158
+ res["remittance_info"] = " ".join(remittance_parts)
159
+
160
+
161
+ def _detect_iban_bic_fallback(text: str, res: dict[str, Any]) -> None:
162
+ """Fallback regex detection for IBAN and BIC if not yet discovered."""
163
+ if not res.get("counterparty_iban"):
164
+ iban_match = _IBAN_RE.search(text)
165
+ if iban_match:
166
+ res["counterparty_iban"] = iban_match.group(0)
167
+
168
+ if not res.get("counterparty_bic"):
169
+ bic_match = _BIC_RE.search(text)
170
+ if bic_match:
171
+ candidate = bic_match.group(0)
172
+ if candidate not in ("NOTPROVIDED", "UNDEFINED"):
173
+ res["counterparty_bic"] = candidate
174
+
175
+
176
+ def parse_field_86(narrative: str | None) -> Field86Structure:
177
+ """Parse a raw SWIFT Field 86 narrative string into structured components.
178
+
179
+ Handles both SWIFT standard slash-separated tags (/EREF/, /REMI/, etc.)
180
+ and German SEPA GVC question-mark codes (?00, ?20, ?32, etc.).
181
+
182
+ Args:
183
+ narrative: Raw :86: string or None.
184
+
185
+ Returns:
186
+ Structured Field86Structure dataclass with extracted fields.
187
+ """
188
+ if not narrative or not narrative.strip():
189
+ return Field86Structure(raw_narrative="")
190
+
191
+ text = narrative.strip()
192
+ res: dict[str, Any] = {
193
+ "raw_narrative": text,
194
+ "additional_tags": {},
195
+ }
196
+
197
+ _parse_gvc_subfields(text, res)
198
+ _parse_slash_subfields(text, res)
199
+ _detect_iban_bic_fallback(text, res)
200
+
201
+ if not res["additional_tags"]:
202
+ res["additional_tags"] = None
203
+
204
+ return Field86Structure(**res)
@@ -0,0 +1,49 @@
1
+ # Copyright (C) 2023-2026 Bank Statement Parser. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
+ # implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Format-specific bank statement parser engines."""
17
+
18
+ from __future__ import annotations
19
+
20
+ from .common import (
21
+ CSV_COLUMN_GROUPS,
22
+ _amount_or_zero,
23
+ _grouped_summaries,
24
+ _normalize_delimiters,
25
+ _normalized_name,
26
+ _parse_amount,
27
+ _read_validated_text,
28
+ _require_amount,
29
+ _summary_text,
30
+ )
31
+ from .csv_parser import CsvStatementParser
32
+ from .mt940 import Mt940Parser
33
+ from .ofx import OfxParser, QfxParser
34
+
35
+ __all__ = [
36
+ "CSV_COLUMN_GROUPS",
37
+ "CsvStatementParser",
38
+ "Mt940Parser",
39
+ "OfxParser",
40
+ "QfxParser",
41
+ "_amount_or_zero",
42
+ "_grouped_summaries",
43
+ "_normalize_delimiters",
44
+ "_normalized_name",
45
+ "_parse_amount",
46
+ "_read_validated_text",
47
+ "_require_amount",
48
+ "_summary_text",
49
+ ]