structured-address-fix 0.1.0__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.
- structured_address_fix-0.1.0/LICENSE +189 -0
- structured_address_fix-0.1.0/PKG-INFO +404 -0
- structured_address_fix-0.1.0/README.md +381 -0
- structured_address_fix-0.1.0/pyproject.toml +129 -0
- structured_address_fix-0.1.0/structured_address_fix/__init__.py +60 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/__init__.py +58 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/_xmlutil.py +146 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/__init__.py +94 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/base.py +122 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/continental.py +81 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/de.py +40 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/fallback.py +50 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/fr.py +40 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/gb.py +90 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/jp.py +88 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/heuristics/us.py +101 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/iso3166.py +140 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/xml_reader.py +207 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/xml_writer.py +244 -0
- structured_address_fix-0.1.0/structured_address_fix/adapters/xpath.py +114 -0
- structured_address_fix-0.1.0/structured_address_fix/config.py +48 -0
- structured_address_fix-0.1.0/structured_address_fix/data/iso3166_alpha2.json +251 -0
- structured_address_fix-0.1.0/structured_address_fix/data/rulebook_clauses/cbpr-2026.json +9 -0
- structured_address_fix-0.1.0/structured_address_fix/data/rulebook_clauses/generic-structured.json +5 -0
- structured_address_fix-0.1.0/structured_address_fix/data/rulebook_clauses/hvps-plus.json +9 -0
- structured_address_fix-0.1.0/structured_address_fix/data/rulebook_clauses/sepa.json +7 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/__init__.py +53 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/address.py +168 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/enums.py +87 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/findings.py +82 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/party.py +40 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/remediation.py +77 -0
- structured_address_fix-0.1.0/structured_address_fix/domain/result.py +57 -0
- structured_address_fix-0.1.0/structured_address_fix/errors.py +138 -0
- structured_address_fix-0.1.0/structured_address_fix/plugins/__init__.py +79 -0
- structured_address_fix-0.1.0/structured_address_fix/plugins/licensing.py +101 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/__init__.py +55 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/base.py +409 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/cbpr_2026.py +108 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/generic_structured.py +67 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/hvps_plus.py +105 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/registry.py +153 -0
- structured_address_fix-0.1.0/structured_address_fix/policies/sepa.py +80 -0
- structured_address_fix-0.1.0/structured_address_fix/services/__init__.py +39 -0
- structured_address_fix-0.1.0/structured_address_fix/services/apply_patch.py +41 -0
- structured_address_fix-0.1.0/structured_address_fix/services/assess.py +105 -0
- structured_address_fix-0.1.0/structured_address_fix/services/classify.py +56 -0
- structured_address_fix-0.1.0/structured_address_fix/services/facade.py +209 -0
- structured_address_fix-0.1.0/structured_address_fix/services/remediate.py +196 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including
|
|
48
|
+
the original version of the Work and any modifications or additions
|
|
49
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
50
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
51
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
52
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
53
|
+
means any form of electronic, verbal, or written communication sent
|
|
54
|
+
to the Licensor or its representatives, including but not limited to
|
|
55
|
+
communication on electronic mailing lists, source code control systems,
|
|
56
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
57
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
58
|
+
excluding communication that is conspicuously marked or otherwise
|
|
59
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
60
|
+
|
|
61
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
62
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
63
|
+
subsequently incorporated within the Work.
|
|
64
|
+
|
|
65
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
66
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
67
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
68
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
69
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
70
|
+
Work and such Derivative Works in Source or Object form.
|
|
71
|
+
|
|
72
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
(except as stated in this section) patent license to make, have made,
|
|
76
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
77
|
+
where such license applies only to those patent claims licensable
|
|
78
|
+
by such Contributor that are necessarily infringed by their
|
|
79
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
80
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
81
|
+
institute patent litigation against any entity (including a
|
|
82
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
83
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
84
|
+
or contributory patent infringement, then any patent licenses
|
|
85
|
+
granted to You under this License for that Work shall terminate
|
|
86
|
+
as of the date such litigation is filed.
|
|
87
|
+
|
|
88
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
89
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
90
|
+
modifications, and in Source or Object form, provided that You
|
|
91
|
+
meet the following conditions:
|
|
92
|
+
|
|
93
|
+
(a) You must give any other recipients of the Work or
|
|
94
|
+
Derivative Works a copy of this License; and
|
|
95
|
+
|
|
96
|
+
(b) You must cause any modified files to carry prominent notices
|
|
97
|
+
stating that You changed the files; and
|
|
98
|
+
|
|
99
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
100
|
+
that You distribute, all copyright, patent, trademark, and
|
|
101
|
+
attribution notices from the Source form of the Work,
|
|
102
|
+
excluding those notices that do not pertain to any part of
|
|
103
|
+
the Derivative Works; and
|
|
104
|
+
|
|
105
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
106
|
+
distribution, then any Derivative Works that You distribute must
|
|
107
|
+
include a readable copy of the attribution notices contained
|
|
108
|
+
within such NOTICE file, excluding any notices that do not
|
|
109
|
+
pertain to any part of the Derivative Works, in at least one
|
|
110
|
+
of the following places: within a NOTICE text file distributed
|
|
111
|
+
as part of the Derivative Works; within the Source form or
|
|
112
|
+
documentation, if provided along with the Derivative Works; or,
|
|
113
|
+
within a display generated by the Derivative Works, if and
|
|
114
|
+
wherever such third-party notices normally appear. The contents
|
|
115
|
+
of the NOTICE file are for informational purposes only and
|
|
116
|
+
do not modify the License. You may add Your own attribution
|
|
117
|
+
notices within Derivative Works that You distribute, alongside
|
|
118
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
119
|
+
that such additional attribution notices cannot be construed
|
|
120
|
+
as modifying the License.
|
|
121
|
+
|
|
122
|
+
You may add Your own copyright statement to Your modifications and
|
|
123
|
+
may provide additional or different license terms and conditions
|
|
124
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
125
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
126
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
127
|
+
the conditions stated in this License.
|
|
128
|
+
|
|
129
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
130
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
131
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
132
|
+
this License, without any additional terms or conditions.
|
|
133
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
134
|
+
the terms of any separate license agreement you may have executed
|
|
135
|
+
with Licensor regarding such Contributions.
|
|
136
|
+
|
|
137
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
138
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
139
|
+
except as required for reasonable and customary use in describing the
|
|
140
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
141
|
+
|
|
142
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
143
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
144
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
145
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
146
|
+
implied, including, without limitation, any warranties or conditions
|
|
147
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
148
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
149
|
+
appropriateness of using or redistributing the Work and assume any
|
|
150
|
+
risks associated with Your exercise of permissions under this License.
|
|
151
|
+
|
|
152
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
153
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
154
|
+
unless required by applicable law (such as deliberate and grossly
|
|
155
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
156
|
+
liable to You for damages, including any direct, indirect, special,
|
|
157
|
+
incidental, or consequential damages of any character arising as a
|
|
158
|
+
result of this License or out of the use or inability to use the
|
|
159
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
160
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
161
|
+
other commercial damages or losses), even if such Contributor
|
|
162
|
+
has been advised of the possibility of such damages.
|
|
163
|
+
|
|
164
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
165
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
166
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
167
|
+
or other liability obligations and/or rights consistent with this
|
|
168
|
+
License. However, in accepting such obligations, You may act only
|
|
169
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
170
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
171
|
+
defend, and hold each Contributor harmless for any liability
|
|
172
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
173
|
+
of your accepting any such warranty or additional liability.
|
|
174
|
+
|
|
175
|
+
END OF TERMS AND CONDITIONS
|
|
176
|
+
|
|
177
|
+
Copyright 2023-2026 Sebastien Rousseau
|
|
178
|
+
|
|
179
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
180
|
+
you may not use this file except in compliance with the License.
|
|
181
|
+
You may obtain a copy of the License at
|
|
182
|
+
|
|
183
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
184
|
+
|
|
185
|
+
Unless required by applicable law or agreed to in writing, software
|
|
186
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
187
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
188
|
+
See the License for the specific language governing permissions and
|
|
189
|
+
limitations under the License.
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: structured-address-fix
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ISO 20022 structured-address remediation and payment-rejection prevention for the November 2026 cliff.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: iso20022,cbpr,postal-address,pacs008,payments,remediation
|
|
8
|
+
Author: Sebastien Rousseau
|
|
9
|
+
Author-email: sebastian.rousseau@gmail.com
|
|
10
|
+
Requires-Python: >=3.12,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Requires-Dist: defusedxml (>=0.7,<0.8)
|
|
17
|
+
Requires-Dist: pydantic (>=2.9,<3)
|
|
18
|
+
Requires-Dist: xmlschema (>=3.4,<5)
|
|
19
|
+
Project-URL: Homepage, https://sebastienrousseau.github.io/structured-address-fix/
|
|
20
|
+
Project-URL: Repository, https://github.com/sebastienrousseau/structured-address-fix
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# structured-address-fix: ISO 20022 Structured-Address Remediation
|
|
24
|
+
|
|
25
|
+
[![PyPI Version][pypi-badge]][pypi-url]
|
|
26
|
+
[![Python Versions][python-versions-badge]][pypi-url]
|
|
27
|
+
[![License][license-badge]][01]
|
|
28
|
+
[![Tests][tests-badge]][tests-url]
|
|
29
|
+
[![Quality][quality-badge]][quality-url]
|
|
30
|
+
[![OpenSSF Scorecard][scorecard-badge]][scorecard-url]
|
|
31
|
+
[![Documentation][docs-badge]][docs-url]
|
|
32
|
+
|
|
33
|
+
**A vendor-neutral core library that detects, scores, and remediates
|
|
34
|
+
non-compliant postal addresses in [ISO 20022][iso] payment messages** —
|
|
35
|
+
ahead of the **14 November 2026** cliff, when fully unstructured addresses
|
|
36
|
+
are rejected across SWIFT CBPR+, HVPS+, T2 RTGS, CHAPS, Fedwire, and Lynx.
|
|
37
|
+
Point it at a `pacs.008` or `pain.001` document, get back an explainable
|
|
38
|
+
list of findings, and turn an `AdrLine`-only address into a structured one
|
|
39
|
+
with reversible, auditable patches.
|
|
40
|
+
|
|
41
|
+
> **The cliff, in one line.** From **14 November 2026** an ISO 20022 postal
|
|
42
|
+
> address that is `AdrLine`-only (unstructured) is non-compliant and liable
|
|
43
|
+
> to be rejected by the major cross-border and high-value schemes. A
|
|
44
|
+
> *hybrid* address (town + country plus at most two residual `AdrLine`
|
|
45
|
+
> lines) is the minimum bar; *structured* is the target. This library exists
|
|
46
|
+
> to move addresses across that line before it bites.
|
|
47
|
+
|
|
48
|
+
## Contents
|
|
49
|
+
|
|
50
|
+
- [Overview](#overview)
|
|
51
|
+
- [The ISO 20022 Suite](#the-iso-20022-suite)
|
|
52
|
+
- [Install](#install)
|
|
53
|
+
- [Quick Start](#quick-start)
|
|
54
|
+
- [Architecture](#architecture)
|
|
55
|
+
- [Policies](#policies)
|
|
56
|
+
- [Premium rule packs](#premium-rule-packs)
|
|
57
|
+
- [Writing a rule pack](#writing-a-rule-pack)
|
|
58
|
+
- [When not to use structured-address-fix](#when-not-to-use-structured-address-fix)
|
|
59
|
+
- [Development](#development)
|
|
60
|
+
- [Security](#security)
|
|
61
|
+
- [Documentation](#documentation)
|
|
62
|
+
- [License](#license)
|
|
63
|
+
- [Contributing](#contributing)
|
|
64
|
+
- [Acknowledgements](#acknowledgements)
|
|
65
|
+
|
|
66
|
+
## Overview
|
|
67
|
+
|
|
68
|
+
`structured-address-fix` is the shared core of a small ISO 20022 address
|
|
69
|
+
toolchain. It reads the postal addresses carried by the parties of a payment
|
|
70
|
+
message (debtor, creditor, agents, ultimate parties), classifies each one as
|
|
71
|
+
**structured**, **hybrid**, or **unstructured** per CBPR+ UG2026, scores the
|
|
72
|
+
compliance risk against a chosen policy, and — where it can — proposes a
|
|
73
|
+
remediation that promotes the address toward the structured target.
|
|
74
|
+
|
|
75
|
+
Two properties are non-negotiable:
|
|
76
|
+
|
|
77
|
+
- **Explainable.** Every remediation is a set of RFC 6902-shaped
|
|
78
|
+
`PatchOperation`s. Each records *why* it exists (the `FindingCode` it
|
|
79
|
+
resolves), *where its value came from* (the originating `AdrLine` token,
|
|
80
|
+
when applicable), and *how confident* the deriving heuristic was. Anything
|
|
81
|
+
it cannot resolve is reported as a **residual finding**, so the gap to full
|
|
82
|
+
compliance is always visible.
|
|
83
|
+
- **Safe by default.** Untrusted XML is parsed with `defusedxml` (no XXE,
|
|
84
|
+
no billion-laughs). The canonical address model is frozen, closed to extra
|
|
85
|
+
fields, and enforces the ISO 20022 element-length maxima as construction
|
|
86
|
+
invariants. Errors raise a typed [`StructuredAddressError`](docs/error-taxonomy.md)
|
|
87
|
+
with a stable `code` and safe `context`.
|
|
88
|
+
|
|
89
|
+
- **Website / docs:** <https://sebastienrousseau.github.io/structured-address-fix/>
|
|
90
|
+
- **Source code:** <https://github.com/sebastienrousseau/structured-address-fix>
|
|
91
|
+
- **Bug reports:** <https://github.com/sebastienrousseau/structured-address-fix/issues>
|
|
92
|
+
|
|
93
|
+
The public surface is the `structured_address_fix.services` facade; the
|
|
94
|
+
domain models are re-exported from the package root for convenience.
|
|
95
|
+
|
|
96
|
+
## The ISO 20022 Suite
|
|
97
|
+
|
|
98
|
+
`structured-address-fix` is the **postal-address remediation core** of the
|
|
99
|
+
sebastienrousseau ISO 20022 suite. It supersedes and generalises the bespoke
|
|
100
|
+
`pacs008.standards.address` module, and it is the shared engine that a thin
|
|
101
|
+
Model Context Protocol server wraps for AI agents — so the classification and
|
|
102
|
+
remediation logic lives in exactly one place and every surface behaves
|
|
103
|
+
identically.
|
|
104
|
+
|
|
105
|
+
| Package | Role |
|
|
106
|
+
| :--- | :--- |
|
|
107
|
+
| **`structured-address-fix`** | **The core library (this package): domain model, policies, adapters, services facade, plugin SDK** |
|
|
108
|
+
| [`structured-address-fix-mcp`](https://github.com/sebastienrousseau/structured-address-fix-mcp) | Thin Model Context Protocol server wrapping the services facade for AI agents |
|
|
109
|
+
| [`pacs008`](https://github.com/sebastienrousseau/pacs008) | FI-to-FI credit-transfer library; delegates its address linting + Nov-2026 readiness here |
|
|
110
|
+
|
|
111
|
+
```mermaid
|
|
112
|
+
flowchart LR
|
|
113
|
+
A["MCP / REST / LSP wrapper"] -->|delegates to| B["structured_address_fix.services"]
|
|
114
|
+
B -->|classify + score + remediate| C["ISO 20022 pacs.008 / pain.001 XML"]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Install
|
|
118
|
+
|
|
119
|
+
`structured-address-fix` runs on macOS, Linux, and Windows and requires
|
|
120
|
+
**Python 3.12+** and **pip**. Its only runtime dependencies are `pydantic`,
|
|
121
|
+
`defusedxml`, and `xmlschema`.
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
python -m pip install structured-address-fix
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
<details>
|
|
128
|
+
<summary>Using an isolated virtual environment (recommended)</summary>
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
python -m venv venv
|
|
132
|
+
source venv/bin/activate # macOS/Linux
|
|
133
|
+
venv\Scripts\activate # Windows
|
|
134
|
+
python -m pip install -U structured-address-fix
|
|
135
|
+
```
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
## Quick Start
|
|
139
|
+
|
|
140
|
+
For the guided tour, see [`docs/quickstart.md`](docs/quickstart.md).
|
|
141
|
+
|
|
142
|
+
### Classify an address
|
|
143
|
+
|
|
144
|
+
The domain model is re-exported from the package root and works standalone.
|
|
145
|
+
`CanonicalAddress` models the ISO 20022 `PostalAddress27` type and classifies
|
|
146
|
+
itself per CBPR+ UG2026:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from structured_address_fix import CanonicalAddress
|
|
150
|
+
|
|
151
|
+
# Unstructured: AdrLine only, no town / country -> rejected from the cliff.
|
|
152
|
+
unstructured = CanonicalAddress(
|
|
153
|
+
address_lines=("221B Baker Street", "London NW1 6XE", "United Kingdom"),
|
|
154
|
+
)
|
|
155
|
+
print(unstructured.classification) # AddressClassification.UNSTRUCTURED
|
|
156
|
+
|
|
157
|
+
# Structured: town + country + structured detail, no residual AdrLine.
|
|
158
|
+
structured = CanonicalAddress(
|
|
159
|
+
building_number="221B",
|
|
160
|
+
street_name="Baker Street",
|
|
161
|
+
post_code="NW1 6XE",
|
|
162
|
+
town_name="London",
|
|
163
|
+
country="GB",
|
|
164
|
+
)
|
|
165
|
+
print(structured.classification) # AddressClassification.STRUCTURED
|
|
166
|
+
|
|
167
|
+
# Serialise back to ISO 20022 element names for the wire.
|
|
168
|
+
structured.model_dump(by_alias=True, exclude_none=True)
|
|
169
|
+
# {'BldgNb': '221B', 'StrtNm': 'Baker Street', 'PstCd': 'NW1 6XE',
|
|
170
|
+
# 'TwnNm': 'London', 'Ctry': 'GB', ...}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Assess and remediate a message
|
|
174
|
+
|
|
175
|
+
The top-level entry point is the `structured_address_fix.services` facade:
|
|
176
|
+
`assess` returns a read-only [`ValidationReport`](docs/remediation-model.md);
|
|
177
|
+
`remediate` adds the proposed fixes (and, optionally, the patched XML):
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from structured_address_fix.services import assess, remediate
|
|
181
|
+
|
|
182
|
+
pacs008_xml = ... # an ISO 20022 pacs.008 document, as text
|
|
183
|
+
|
|
184
|
+
# 1. Score every party's address against a policy.
|
|
185
|
+
report = assess(pacs008_xml, policy="cbpr-2026")
|
|
186
|
+
print(report.is_compliant) # False
|
|
187
|
+
for finding in report.findings:
|
|
188
|
+
print(finding.code, finding.party_role, finding.message)
|
|
189
|
+
# SAF001 Dbtr Address is AdrLine-only; rejected from 2026-11-14
|
|
190
|
+
|
|
191
|
+
# 2. Propose reversible, explainable patches for what can be fixed.
|
|
192
|
+
result = remediate(pacs008_xml, policy="cbpr-2026")
|
|
193
|
+
for suggestion in result.suggestions:
|
|
194
|
+
print(suggestion.before.classification, "->",
|
|
195
|
+
suggestion.after.classification) # unstructured -> hybrid
|
|
196
|
+
for op in suggestion.operations:
|
|
197
|
+
print(op.op, op.path, op.reason_code, op.confidence)
|
|
198
|
+
# Anything no heuristic could resolve is reported, never hidden:
|
|
199
|
+
for residual in suggestion.residual_findings:
|
|
200
|
+
print("residual:", residual.code)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
> The built-in policies, XML adapters, per-country heuristics, and the
|
|
204
|
+
> `assess` / `remediate` facade land in the v0.1.x series; see
|
|
205
|
+
> [`ROADMAP.md`](ROADMAP.md). The domain model and error taxonomy shipped in
|
|
206
|
+
> v0.1.0 and are stable.
|
|
207
|
+
|
|
208
|
+
## Architecture
|
|
209
|
+
|
|
210
|
+
The library is layered so that each concern is testable in isolation and the
|
|
211
|
+
public surface stays small. Dependencies point downward only.
|
|
212
|
+
|
|
213
|
+
| Layer | Module | Responsibility |
|
|
214
|
+
| :--- | :--- | :--- |
|
|
215
|
+
| **Domain** | `structured_address_fix.domain` | Pure Pydantic v2 entities and their invariants, with zero I/O: `CanonicalAddress`, `AddressedParty`, `RiskFinding`, `PatchOperation`, the result envelopes, and the wire-facing enums. |
|
|
216
|
+
| **Policies** | `structured_address_fix.policies` | Rulebooks that inspect a `CanonicalAddress` and raise `RiskFinding`s: the four built-ins (see below), each citing a rulebook clause. |
|
|
217
|
+
| **Adapters** | `structured_address_fix.adapters` | `defusedxml` parsing of pacs.008 / pain.001, party discovery, and the per-country `AdrLine` → structured heuristics that populate the canonical model with recorded confidence + source tokens. |
|
|
218
|
+
| **Services** | `structured_address_fix.services` | The `assess` / `remediate` facade — the single public entry point wrappers (MCP / REST / LSP) call. |
|
|
219
|
+
| **Plugins** | `structured_address_fix.plugins` | The premium rule-pack SDK: entry-point discovery of third-party `PolicyPack`s, gated by entitlement + integrity checks. |
|
|
220
|
+
|
|
221
|
+
## Policies
|
|
222
|
+
|
|
223
|
+
A **policy** is a rulebook: it names the finding codes that apply and the
|
|
224
|
+
severity each carries. Four are built in and open-source:
|
|
225
|
+
|
|
226
|
+
| Policy id | Scope | Use it when |
|
|
227
|
+
| :--- | :--- | :--- |
|
|
228
|
+
| `cbpr-2026` | SWIFT CBPR+ UG2026 cross-border requirements — the Nov-2026 cliff rules. **The default.** | You send or receive cross-border SWIFT payments |
|
|
229
|
+
| `sepa` | SEPA credit-transfer address expectations | You operate in the euro retail-payment area |
|
|
230
|
+
| `hvps-plus` | HVPS+ high-value / RTGS market-practice (T2, CHAPS, Fedwire, Lynx) | You settle over a high-value system |
|
|
231
|
+
| `generic-structured` | Scheme-agnostic structured-vs-unstructured hygiene | You want the baseline structural checks with no scheme assumptions |
|
|
232
|
+
|
|
233
|
+
The default policy is `cbpr-2026`, overridable per call or via the
|
|
234
|
+
`SAF_DEFAULT_POLICY` environment variable. Finding codes (`SAF001`–`SAF008`)
|
|
235
|
+
are a stable public API: a code's meaning is fixed once released. See
|
|
236
|
+
[`docs/policies.md`](docs/policies.md) for the full rule-to-code mapping and
|
|
237
|
+
[`docs/error-taxonomy.md`](docs/error-taxonomy.md) for the exception codes.
|
|
238
|
+
|
|
239
|
+
## Premium rule packs
|
|
240
|
+
|
|
241
|
+
The four built-in policies cover the open, published scheme rules. Some
|
|
242
|
+
requirements — proprietary market-practice profiles, correspondent-specific
|
|
243
|
+
overlays, jurisdiction-specific address validation — are better shipped as
|
|
244
|
+
**premium rule packs**: separately installable Python distributions that
|
|
245
|
+
register additional policies through an entry point.
|
|
246
|
+
|
|
247
|
+
A pack is discovered automatically once installed, contributes its own policy
|
|
248
|
+
ids and finding codes (with their own prefixes, so they never collide with the
|
|
249
|
+
core `SAF` codes), and is gated at load time by the entitlement + integrity
|
|
250
|
+
checks in the [error taxonomy](docs/error-taxonomy.md)
|
|
251
|
+
(`PackNotLicensedError`, `PackIntegrityError`). The core never bundles a pack;
|
|
252
|
+
you opt in by installing one.
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from structured_address_fix.services import assess
|
|
256
|
+
|
|
257
|
+
# A premium pack's policy id, resolved through the plugin registry.
|
|
258
|
+
report = assess(message_xml, policy="acme-correspondent-2026")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Writing a rule pack
|
|
262
|
+
|
|
263
|
+
Publishing a rule pack means shipping a `PolicyPack` and advertising it under
|
|
264
|
+
the `structured_address_fix.policies` entry-point group:
|
|
265
|
+
|
|
266
|
+
```toml
|
|
267
|
+
# pyproject.toml of your pack distribution
|
|
268
|
+
[project.entry-points."structured_address_fix.policies"]
|
|
269
|
+
acme-correspondent-2026 = "acme_saf_pack:PACK"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
# acme_saf_pack/__init__.py
|
|
274
|
+
from structured_address_fix.domain import (
|
|
275
|
+
FindingCode, RiskFinding, Severity, CanonicalAddress,
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
def check(address: CanonicalAddress, *, location: str) -> list[RiskFinding]:
|
|
279
|
+
"""Raise the pack's findings against a single address."""
|
|
280
|
+
findings: list[RiskFinding] = []
|
|
281
|
+
if address.post_code is None:
|
|
282
|
+
findings.append(RiskFinding(
|
|
283
|
+
code=FindingCode.MISSING_TOWN, # or a pack-specific code
|
|
284
|
+
severity=Severity.ERROR,
|
|
285
|
+
message="Correspondent profile requires a post code.",
|
|
286
|
+
policy_id="acme-correspondent-2026",
|
|
287
|
+
location=location,
|
|
288
|
+
))
|
|
289
|
+
return findings
|
|
290
|
+
|
|
291
|
+
PACK = ... # a PolicyPack binding the id "acme-correspondent-2026" to check()
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The full contract — the `PolicyPack` shape, custom finding-code prefixes,
|
|
295
|
+
entitlement, and integrity signing — is in
|
|
296
|
+
[`docs/writing-a-rule-pack.md`](docs/writing-a-rule-pack.md).
|
|
297
|
+
|
|
298
|
+
## When not to use structured-address-fix
|
|
299
|
+
|
|
300
|
+
- **Your addresses are already fully structured.** If every message you send
|
|
301
|
+
already carries `TwnNm` + `Ctry` + structured detail and no `AdrLine`,
|
|
302
|
+
there is nothing to remediate; a one-off `assess` to confirm compliance is
|
|
303
|
+
all you need.
|
|
304
|
+
- **You need to *generate* whole payment messages.** This library remediates
|
|
305
|
+
the postal-address portion of an existing message; it does not build a
|
|
306
|
+
pacs.008 or pain.001 from scratch. Use the message-family libraries for
|
|
307
|
+
that (e.g. `pacs008`, `pain001`).
|
|
308
|
+
- **You want an agent tool, not a library import.** Use the thin
|
|
309
|
+
[`structured-address-fix-mcp`](https://github.com/sebastienrousseau/structured-address-fix-mcp)
|
|
310
|
+
server, which wraps this facade for MCP clients.
|
|
311
|
+
- **You need authoritative address verification against a postal database.**
|
|
312
|
+
The `AdrLine` → structured heuristics are deterministic, explainable
|
|
313
|
+
best-effort splits with recorded confidence; they do not consult a national
|
|
314
|
+
address file. Low-confidence or unresolvable fragments are reported as
|
|
315
|
+
residual findings for a human to resolve, never silently guessed.
|
|
316
|
+
- **You need a schema validator.** For pure XSD validation of a whole
|
|
317
|
+
document, use `xmlschema` directly; this library focuses on address
|
|
318
|
+
compliance, not full-message schema conformance.
|
|
319
|
+
|
|
320
|
+
## Development
|
|
321
|
+
|
|
322
|
+
`structured-address-fix` uses [Poetry](https://python-poetry.org/) and
|
|
323
|
+
[mise](https://mise.jdx.dev/).
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
git clone https://github.com/sebastienrousseau/structured-address-fix.git && cd structured-address-fix
|
|
327
|
+
mise install
|
|
328
|
+
poetry install
|
|
329
|
+
poetry shell
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
A `Makefile` orchestrates the quality gates (kept in lockstep with CI):
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
make check # lint + type-check + test (REQUIRED before commit)
|
|
336
|
+
make test # pytest at 100% line + branch coverage
|
|
337
|
+
make lint # ruff + black --check
|
|
338
|
+
make type-check # mypy --strict
|
|
339
|
+
make security # bandit
|
|
340
|
+
make examples # run each examples/*.py
|
|
341
|
+
make pip-compile # regenerate hash-pinned requirements/*.txt from *.in
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Security
|
|
345
|
+
|
|
346
|
+
Untrusted ISO 20022 XML is parsed with `defusedxml`, never the standard-library
|
|
347
|
+
parser, so XXE / billion-laughs / external-DTD attacks are structurally
|
|
348
|
+
prevented. The canonical model is frozen and `extra="forbid"`, and every error
|
|
349
|
+
is a typed `StructuredAddressError` with a stable `code` and safe `context`, so
|
|
350
|
+
a wrapping transport can serialise `{"error": ...}` payloads rather than leaking
|
|
351
|
+
tracebacks. Premium rule packs are opt-in and gated by entitlement + integrity
|
|
352
|
+
checks. Reporting practice, supported versions, the NIST SSDF practice mapping,
|
|
353
|
+
and the accepted OpenSSF Scorecard findings are documented in
|
|
354
|
+
[`SECURITY.md`](SECURITY.md). Vulnerabilities go via GitHub Private
|
|
355
|
+
Vulnerability Reporting, not public issues.
|
|
356
|
+
|
|
357
|
+
## Documentation
|
|
358
|
+
|
|
359
|
+
- [`README.md`](README.md) — this file
|
|
360
|
+
- [`docs/index.md`](docs/index.md) — documentation index
|
|
361
|
+
- [`docs/quickstart.md`](docs/quickstart.md) — guided tour
|
|
362
|
+
- [`docs/policies.md`](docs/policies.md) — the built-in policies and their rules
|
|
363
|
+
- [`docs/writing-a-rule-pack.md`](docs/writing-a-rule-pack.md) — the premium rule-pack contract
|
|
364
|
+
- [`docs/remediation-model.md`](docs/remediation-model.md) — findings, patches, and results
|
|
365
|
+
- [`docs/error-taxonomy.md`](docs/error-taxonomy.md) — the exception codes
|
|
366
|
+
- [`docs/nov-2026-cutover.md`](docs/nov-2026-cutover.md) — the Nov-2026 cliff, scheme by scheme
|
|
367
|
+
- [`CHANGELOG.md`](CHANGELOG.md) — release notes
|
|
368
|
+
- [`SECURITY.md`](SECURITY.md) — disclosure + supported versions
|
|
369
|
+
- [`ROADMAP.md`](ROADMAP.md) — where the project is going
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
Licensed under the [Apache License, Version 2.0][01]. Any contribution submitted
|
|
374
|
+
for inclusion shall be licensed as above, without additional terms.
|
|
375
|
+
|
|
376
|
+
## Contributing
|
|
377
|
+
|
|
378
|
+
Contributions are welcome — see the [contributing instructions][04]. Thanks to
|
|
379
|
+
all [contributors][05].
|
|
380
|
+
|
|
381
|
+
## Acknowledgements
|
|
382
|
+
|
|
383
|
+
Built on [Pydantic](https://docs.pydantic.dev/), [defusedxml][defusedxml], and
|
|
384
|
+
[xmlschema](https://github.com/sissaschool/xmlschema), and grounded in the
|
|
385
|
+
ISO 20022 CBPR+ / HVPS+ structured-address requirements.
|
|
386
|
+
|
|
387
|
+
[01]: https://opensource.org/license/apache-2-0/
|
|
388
|
+
[04]: https://github.com/sebastienrousseau/structured-address-fix/blob/main/CONTRIBUTING.md
|
|
389
|
+
[05]: https://github.com/sebastienrousseau/structured-address-fix/graphs/contributors
|
|
390
|
+
[iso]: https://www.iso20022.org
|
|
391
|
+
[defusedxml]: https://github.com/tiran/defusedxml
|
|
392
|
+
[docs-badge]: https://img.shields.io/badge/Docs-structured--address--fix-blue?style=for-the-badge
|
|
393
|
+
[docs-url]: https://sebastienrousseau.github.io/structured-address-fix/
|
|
394
|
+
[license-badge]: https://img.shields.io/pypi/l/structured-address-fix?style=for-the-badge
|
|
395
|
+
[pypi-badge]: https://img.shields.io/pypi/v/structured-address-fix?style=for-the-badge
|
|
396
|
+
[pypi-url]: https://pypi.org/project/structured-address-fix/
|
|
397
|
+
[python-versions-badge]: https://img.shields.io/pypi/pyversions/structured-address-fix.svg?style=for-the-badge
|
|
398
|
+
[quality-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/structured-address-fix/ci.yml?branch=main&label=Quality&style=for-the-badge
|
|
399
|
+
[quality-url]: https://github.com/sebastienrousseau/structured-address-fix/actions/workflows/ci.yml
|
|
400
|
+
[scorecard-badge]: https://api.scorecard.dev/projects/github.com/sebastienrousseau/structured-address-fix/badge?style=for-the-badge
|
|
401
|
+
[scorecard-url]: https://scorecard.dev/viewer/?uri=github.com/sebastienrousseau/structured-address-fix
|
|
402
|
+
[tests-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/structured-address-fix/ci.yml?branch=main&label=Tests&style=for-the-badge
|
|
403
|
+
[tests-url]: https://github.com/sebastienrousseau/structured-address-fix/actions/workflows/ci.yml
|
|
404
|
+
|