sdc-gdr2edifact 4.0.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.
Files changed (27) hide show
  1. sdc_gdr2edifact-4.0.0/LICENSE +201 -0
  2. sdc_gdr2edifact-4.0.0/NOTICE +14 -0
  3. sdc_gdr2edifact-4.0.0/PKG-INFO +153 -0
  4. sdc_gdr2edifact-4.0.0/README.md +132 -0
  5. sdc_gdr2edifact-4.0.0/pyproject.toml +38 -0
  6. sdc_gdr2edifact-4.0.0/setup.cfg +4 -0
  7. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/__init__.py +28 -0
  8. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/check.py +167 -0
  9. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/directory.py +299 -0
  10. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mapper.py +130 -0
  11. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/credit_note-jkuyr38hydqaiwlq5vhp2rjr.yaml +529 -0
  12. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/despatch_advice-cacl4njrwanj15g3p3so8t6h.yaml +378 -0
  13. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/invoice-u19w614300a8ot4a7qnn2o1c.yaml +514 -0
  14. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/order-h8bttbt9afwzf9zs4jhae566.yaml +442 -0
  15. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/order_response-kuntv2wlkw54h7nxe0kqhvi2.yaml +598 -0
  16. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/receipt_advice-tog0v0p1zit1xwpxysxwpf3d.yaml +366 -0
  17. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/remittance_advice-fgtbf38cj0bwxppxn69etcci.yaml +246 -0
  18. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/mappings/torvale_order-cq1fjrvyn0fxl1kyk9y3kr1w.yaml +448 -0
  19. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact/writer.py +383 -0
  20. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/PKG-INFO +153 -0
  21. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/SOURCES.txt +25 -0
  22. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/dependency_links.txt +1 -0
  23. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/entry_points.txt +2 -0
  24. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/requires.txt +7 -0
  25. sdc_gdr2edifact-4.0.0/src/sdc_gdr2edifact.egg-info/top_level.txt +1 -0
  26. sdc_gdr2edifact-4.0.0/tests/test_edifact.py +152 -0
  27. sdc_gdr2edifact-4.0.0/tests/test_messages.py +95 -0
@@ -0,0 +1,201 @@
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
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,14 @@
1
+ Copyright 2026 Axius SDC, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0.
4
+
5
+ The UN/EDIFACT directory is not part of this package or this repository. The package reads the archive each user
6
+ downloads from UNECE (https://unece.org/trade/uncefact/unedifact/download), unmodified; the directory is © United
7
+ Nations and licensed by the UN on the terms of the license agreement inside the archive (LICENAGR.TXT).
8
+
9
+ The test fixtures under samples/ are the published packages of the eight models of the business documents library and
10
+ 293 records generated by HalvorsenDemo (https://github.com/SemanticDataCharter/HalvorsenDemo, Apache 2.0);
11
+ tests/golden/ holds five DESADV interchanges written from those records by the UN-EDIFACT library's DESADV writer. The
12
+ companies and documents are fictitious.
13
+
14
+ The tests use pydifact (https://github.com/nerdocs/pydifact, MIT) as an independent parser.
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: sdc-gdr2edifact
3
+ Version: 4.0.0
4
+ Summary: Governed Data Records as conformant UN/EDIFACT D.24A interchanges, through sdc-mapper: one mapping file per model, every value reported.
5
+ Author: Axius SDC, Inc.
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/SemanticDataCharter/sdc-gdr2edifact
8
+ Keywords: sdc,semantic data charter,governed data record,edifact,un/edifact,unece,mapping
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Requires-Dist: sdc-mapper<5,>=4.2
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8.0; extra == "dev"
17
+ Requires-Dist: pyyaml>=6.0; extra == "dev"
18
+ Requires-Dist: lxml>=5.0; extra == "dev"
19
+ Requires-Dist: pydifact>=0.2; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # sdc-gdr2edifact
23
+
24
+ Governed Data Records as UN/EDIFACT D.24A interchanges. A target mapper for
25
+ [sdc-mapper](https://github.com/SemanticDataCharter/sdc-mapper): the core validates the record, resolves every value
26
+ against its model and reports each one; this package says where each value goes in a message and writes the
27
+ interchange, UNA to UNZ. Outbound only. Apache 2.0.
28
+
29
+ **Status:** 4.0.0 in development. Every document of the business documents library has a mapping:
30
+
31
+ | Model | ct_id | Message | Rules |
32
+ |---|---|---|---|
33
+ | Order | `h8bttbt9afwzf9zs4jhae566` | ORDERS | 213 |
34
+ | Torvale Order (profile) | `cq1fjrvyn0fxl1kyk9y3kr1w` | ORDERS | 216 |
35
+ | Order Response | `kuntv2wlkw54h7nxe0kqhvi2` | ORDRSP | 291 |
36
+ | Despatch Advice | `cacl4njrwanj15g3p3so8t6h` | DESADV | 181 |
37
+ | Receipt Advice | `tog0v0p1zit1xwpxysxwpf3d` | RECADV | 175 |
38
+ | Invoice | `u19w614300a8ot4a7qnn2o1c` | INVOIC (380) | 249 |
39
+ | Credit Note | `jkuyr38hydqaiwlq5vhp2rjr` | INVOIC (381) | 256 |
40
+ | Remittance Advice | `fgtbf38cj0bwxppxn69etcci` | REMADV | 115 |
41
+
42
+ ## Use
43
+
44
+ The directory is not part of this package (see the terms below). Download the D.24A archive from UNECE
45
+ (https://unece.org/trade/uncefact/unedifact/download) and point the mapper at the zip, unchanged:
46
+
47
+ ```
48
+ export SDC_EDIFACT_DIRECTORY=/path/to/d24a.zip
49
+ sdc-map map edifact despatch-advice.xml --package DIR --mapping "$(python -c 'from sdc_gdr2edifact import mapping_path; print(mapping_path("cacl4njrwanj15g3p3so8t6h"))')"
50
+ ```
51
+
52
+ ```python
53
+ from sdc_mapper import Engine, load_mapping
54
+ from sdc_gdr2edifact import EDIFACTMapper, mapping_path
55
+
56
+ mapper = EDIFACTMapper("/path/to/d24a.zip") # or $SDC_EDIFACT_DIRECTORY
57
+ result = Engine().map_record(xml, mapper, load_mapping(mapping_path("cacl4njrwanj15g3p3so8t6h")))
58
+ result.files["DESADV.edi"] # UNA ... UNB ... UNH ... UNT ... UNZ, ISO 8859-1 (UNOC)
59
+ result.report # every value: declared, lookup or not representable, and why
60
+ ```
61
+
62
+ Through sdc-mapper's MCP server the mapper is the target `edifact`.
63
+
64
+ ## The target and its terms
65
+
66
+ **UN/EDIFACT**, the United Nations rules for electronic data interchange: the syntax is ISO 9735, and UNECE publishes
67
+ the directory (UNTDID: data elements, composites, segments, code lists, message specifications) twice a year. This
68
+ package writes **D.24A**, read from the archive UNECE published on 9 October 2024.
69
+
70
+ The directory comes with UNECE's license agreement (`LICENAGR.TXT` in the archive). It grants use of the directory
71
+ within the organization, in the country where it was acquired or where the organization is located; copies for use and
72
+ backup within the organization; and distribution of copies of the original file as downloaded, with the license. It
73
+ does not allow selling, sub-licensing, renting, leasing or assigning the directory, or modifying it and distributing
74
+ the result, without the UN's written permission. So:
75
+
76
+ - **This package carries no part of the directory.** It reads the archive the user downloaded, as downloaded, and
77
+ keeps its extraction as a working copy in the user's cache (`~/.cache/sdc-gdr2edifact/`), on the user's machine.
78
+ - **This repository** does not carry the directory either: the tests read the archive from `SDC_EDIFACT_DIRECTORY`.
79
+ - **GS1's EANCOM** (UN/EDIFACT's retail subset) is not a target until its terms are confirmed.
80
+
81
+ Every interchange this package writes conforms to the D.24A message specification, or is not written.
82
+
83
+ ## Where values go: declared, one mapping file per model
84
+
85
+ The business documents library links its components to UBL, not to UN/EDIFACT, so where a value goes in a message (the
86
+ segment, its qualifier, the data element) is stated in a mapping file, `src/sdc_gdr2edifact/mappings/<document>-<ct_id>.yaml`,
87
+ bound to the model's schema by its SHA-256. The qualifiers are the UN-EDIFACT library's mappings (`mapping/*.json`,
88
+ reviewed by hand on 4 October 2026, from which the library's D.24A qualifier tokens were published).
89
+
90
+ Where the model binds a value to a code list the directory uses, the value is a **lookup**: the business documents bind
91
+ the payment means to UBL 2.3's PaymentMeansCode list, which is UNCL 4461 code for code (checked against D.24A), so
92
+ PAI's 4461 is the model's own code. The handling unit and packaging types are bound to the UN/ECE Recommendations'
93
+ page without a code, so their Recommendation 21 codes are declared, as the Recommendation 20 unit codes are. The
94
+ allowance and charge reason is bound to UBL's AllowanceChargeReasonCode, which is UNCL 4465 (adjustment reasons); ALC
95
+ identifies an allowance with a different list (5189), so the reason travels as ALC's text (C214 7160) and its code
96
+ does not.
97
+
98
+ The mapping files are written with `tools/build_mapping.py` from a spec in the model's labels (`tools/specs/`: one per
99
+ message, composed with the rules every library document shares in `common.py`), which checks that every value the
100
+ model can hold reaches a rule: placed, or omitted with a reason.
101
+
102
+ **DESADV and the library's writer.** For all 52 Despatch Advice records, this mapping and the UN-EDIFACT library's
103
+ hand-written DESADV writer (`edifact/desadv.py`) produce the same segments with the same data, and the library's reader
104
+ reads the same values from both; the order of repeated segments within a group (references, dates, measurements) is
105
+ the record's here. Five are kept in `tests/golden/`. The other five messages had paper mappings only; their
106
+ placements are this package's first writers.
107
+
108
+ ## What UN/EDIFACT cannot say
109
+
110
+ - **Exceptional Values.** UN/EDIFACT has no null flavors. A free text segment could hold the words, but no qualifier
111
+ the directory defines says "this value was asked for and refused" in a way a receiving system would act on, so an
112
+ Exceptional Value is **lost**, every ISO 21090 code alike, and the report says so. A mapping file cannot promise
113
+ otherwise. Where the directory requires the value, the segment or group cannot be written and its other values are
114
+ reported with the reason; where the interchange requires it (the sender's or the recipient's identification in
115
+ UNB), there is no interchange, and the call ends as an error that says which element.
116
+ - **The record's provenance and audit**, the validity windows and recording times (act, vtb, vte, tr), and the
117
+ definitions each component is bound to.
118
+ - Across the 293 sample records, 80.9% of the business values are placed (44,308 declared, 189 lookups) and 10,478 are
119
+ not representable, each with its reason. The largest: the UBL-facing identifiers (customization, profile, UUID),
120
+ which UNH and BGM already settle; a document reference's type and description (a reference group carries a number
121
+ and a date); an address's use, a party's endpoint and a contact's department; a tax scheme's own identifier and a
122
+ tax category's name (TAX codes them); flags with no element (partial delivery, back order, free of charge); a
123
+ receipt check's result (CDI states a condition by a code a partner agrees); a pallet build pattern.
124
+
125
+ ## How the writer works
126
+
127
+ A message is written as a tree first: its root is the message type, `SG<n>` a segment group, a tag a segment, and
128
+ `~x` after either tells apart segments of the same tag (`DTM~137`, `SG1~ON`). A segment's data are attributes named by
129
+ the directory: `@3035`, `@C082.3039`, `@C080.3036#2` for a component's second occurrence, `@C212#2.7140` for a
130
+ composite's second occurrence in its segment; a trailing `+` appends (a time after a date). From the directory the
131
+ writer orders every group as the message specification does; adds a group's trigger segment when it has no mandatory
132
+ data (an empty PCI) and numbers CPS hierarchies; removes a segment that lacks mandatory data, and a group that lacks its
133
+ trigger, with the reason; continues a value too long for its component into the components of the same tag that
134
+ follow (a long name across C080's 3036s, shipping marks across PCI's 7102s); infers a DTM's format (102, 203, 204); and
135
+ writes UNA, UNB, UNH, UNS where the message has one, UNT with the segment count, and UNZ. The interchange and message
136
+ control references are the document's number (its last 14 word characters).
137
+
138
+ **The check is independent.** `sdc_gdr2edifact.check` parses the interchange from its text, by code that shares
139
+ nothing with the writer, and checks the envelope (counts, references), the segment sequence against the message
140
+ specification's segment table, and every segment against its definition; the tests also parse every interchange with
141
+ [pydifact](https://github.com/nerdocs/pydifact) (MIT), which has no D.24A definitions but reads the syntax.
142
+
143
+ ## Tests
144
+
145
+ ```
146
+ pip install -e ".[dev]"
147
+ SDC_EDIFACT_DIRECTORY=/path/to/d24a.zip python -m pytest
148
+ ```
149
+
150
+ Without `SDC_EDIFACT_DIRECTORY`, every test that needs the directory is skipped and says so.
151
+
152
+ Every sample record of the eight models is mapped, checked and parsed; the DESADV is compared with the library's
153
+ writer; Exceptional Values, refused mappings and a tampered interchange are exercised.
@@ -0,0 +1,132 @@
1
+ # sdc-gdr2edifact
2
+
3
+ Governed Data Records as UN/EDIFACT D.24A interchanges. A target mapper for
4
+ [sdc-mapper](https://github.com/SemanticDataCharter/sdc-mapper): the core validates the record, resolves every value
5
+ against its model and reports each one; this package says where each value goes in a message and writes the
6
+ interchange, UNA to UNZ. Outbound only. Apache 2.0.
7
+
8
+ **Status:** 4.0.0 in development. Every document of the business documents library has a mapping:
9
+
10
+ | Model | ct_id | Message | Rules |
11
+ |---|---|---|---|
12
+ | Order | `h8bttbt9afwzf9zs4jhae566` | ORDERS | 213 |
13
+ | Torvale Order (profile) | `cq1fjrvyn0fxl1kyk9y3kr1w` | ORDERS | 216 |
14
+ | Order Response | `kuntv2wlkw54h7nxe0kqhvi2` | ORDRSP | 291 |
15
+ | Despatch Advice | `cacl4njrwanj15g3p3so8t6h` | DESADV | 181 |
16
+ | Receipt Advice | `tog0v0p1zit1xwpxysxwpf3d` | RECADV | 175 |
17
+ | Invoice | `u19w614300a8ot4a7qnn2o1c` | INVOIC (380) | 249 |
18
+ | Credit Note | `jkuyr38hydqaiwlq5vhp2rjr` | INVOIC (381) | 256 |
19
+ | Remittance Advice | `fgtbf38cj0bwxppxn69etcci` | REMADV | 115 |
20
+
21
+ ## Use
22
+
23
+ The directory is not part of this package (see the terms below). Download the D.24A archive from UNECE
24
+ (https://unece.org/trade/uncefact/unedifact/download) and point the mapper at the zip, unchanged:
25
+
26
+ ```
27
+ export SDC_EDIFACT_DIRECTORY=/path/to/d24a.zip
28
+ sdc-map map edifact despatch-advice.xml --package DIR --mapping "$(python -c 'from sdc_gdr2edifact import mapping_path; print(mapping_path("cacl4njrwanj15g3p3so8t6h"))')"
29
+ ```
30
+
31
+ ```python
32
+ from sdc_mapper import Engine, load_mapping
33
+ from sdc_gdr2edifact import EDIFACTMapper, mapping_path
34
+
35
+ mapper = EDIFACTMapper("/path/to/d24a.zip") # or $SDC_EDIFACT_DIRECTORY
36
+ result = Engine().map_record(xml, mapper, load_mapping(mapping_path("cacl4njrwanj15g3p3so8t6h")))
37
+ result.files["DESADV.edi"] # UNA ... UNB ... UNH ... UNT ... UNZ, ISO 8859-1 (UNOC)
38
+ result.report # every value: declared, lookup or not representable, and why
39
+ ```
40
+
41
+ Through sdc-mapper's MCP server the mapper is the target `edifact`.
42
+
43
+ ## The target and its terms
44
+
45
+ **UN/EDIFACT**, the United Nations rules for electronic data interchange: the syntax is ISO 9735, and UNECE publishes
46
+ the directory (UNTDID: data elements, composites, segments, code lists, message specifications) twice a year. This
47
+ package writes **D.24A**, read from the archive UNECE published on 9 October 2024.
48
+
49
+ The directory comes with UNECE's license agreement (`LICENAGR.TXT` in the archive). It grants use of the directory
50
+ within the organization, in the country where it was acquired or where the organization is located; copies for use and
51
+ backup within the organization; and distribution of copies of the original file as downloaded, with the license. It
52
+ does not allow selling, sub-licensing, renting, leasing or assigning the directory, or modifying it and distributing
53
+ the result, without the UN's written permission. So:
54
+
55
+ - **This package carries no part of the directory.** It reads the archive the user downloaded, as downloaded, and
56
+ keeps its extraction as a working copy in the user's cache (`~/.cache/sdc-gdr2edifact/`), on the user's machine.
57
+ - **This repository** does not carry the directory either: the tests read the archive from `SDC_EDIFACT_DIRECTORY`.
58
+ - **GS1's EANCOM** (UN/EDIFACT's retail subset) is not a target until its terms are confirmed.
59
+
60
+ Every interchange this package writes conforms to the D.24A message specification, or is not written.
61
+
62
+ ## Where values go: declared, one mapping file per model
63
+
64
+ The business documents library links its components to UBL, not to UN/EDIFACT, so where a value goes in a message (the
65
+ segment, its qualifier, the data element) is stated in a mapping file, `src/sdc_gdr2edifact/mappings/<document>-<ct_id>.yaml`,
66
+ bound to the model's schema by its SHA-256. The qualifiers are the UN-EDIFACT library's mappings (`mapping/*.json`,
67
+ reviewed by hand on 4 October 2026, from which the library's D.24A qualifier tokens were published).
68
+
69
+ Where the model binds a value to a code list the directory uses, the value is a **lookup**: the business documents bind
70
+ the payment means to UBL 2.3's PaymentMeansCode list, which is UNCL 4461 code for code (checked against D.24A), so
71
+ PAI's 4461 is the model's own code. The handling unit and packaging types are bound to the UN/ECE Recommendations'
72
+ page without a code, so their Recommendation 21 codes are declared, as the Recommendation 20 unit codes are. The
73
+ allowance and charge reason is bound to UBL's AllowanceChargeReasonCode, which is UNCL 4465 (adjustment reasons); ALC
74
+ identifies an allowance with a different list (5189), so the reason travels as ALC's text (C214 7160) and its code
75
+ does not.
76
+
77
+ The mapping files are written with `tools/build_mapping.py` from a spec in the model's labels (`tools/specs/`: one per
78
+ message, composed with the rules every library document shares in `common.py`), which checks that every value the
79
+ model can hold reaches a rule: placed, or omitted with a reason.
80
+
81
+ **DESADV and the library's writer.** For all 52 Despatch Advice records, this mapping and the UN-EDIFACT library's
82
+ hand-written DESADV writer (`edifact/desadv.py`) produce the same segments with the same data, and the library's reader
83
+ reads the same values from both; the order of repeated segments within a group (references, dates, measurements) is
84
+ the record's here. Five are kept in `tests/golden/`. The other five messages had paper mappings only; their
85
+ placements are this package's first writers.
86
+
87
+ ## What UN/EDIFACT cannot say
88
+
89
+ - **Exceptional Values.** UN/EDIFACT has no null flavors. A free text segment could hold the words, but no qualifier
90
+ the directory defines says "this value was asked for and refused" in a way a receiving system would act on, so an
91
+ Exceptional Value is **lost**, every ISO 21090 code alike, and the report says so. A mapping file cannot promise
92
+ otherwise. Where the directory requires the value, the segment or group cannot be written and its other values are
93
+ reported with the reason; where the interchange requires it (the sender's or the recipient's identification in
94
+ UNB), there is no interchange, and the call ends as an error that says which element.
95
+ - **The record's provenance and audit**, the validity windows and recording times (act, vtb, vte, tr), and the
96
+ definitions each component is bound to.
97
+ - Across the 293 sample records, 80.9% of the business values are placed (44,308 declared, 189 lookups) and 10,478 are
98
+ not representable, each with its reason. The largest: the UBL-facing identifiers (customization, profile, UUID),
99
+ which UNH and BGM already settle; a document reference's type and description (a reference group carries a number
100
+ and a date); an address's use, a party's endpoint and a contact's department; a tax scheme's own identifier and a
101
+ tax category's name (TAX codes them); flags with no element (partial delivery, back order, free of charge); a
102
+ receipt check's result (CDI states a condition by a code a partner agrees); a pallet build pattern.
103
+
104
+ ## How the writer works
105
+
106
+ A message is written as a tree first: its root is the message type, `SG<n>` a segment group, a tag a segment, and
107
+ `~x` after either tells apart segments of the same tag (`DTM~137`, `SG1~ON`). A segment's data are attributes named by
108
+ the directory: `@3035`, `@C082.3039`, `@C080.3036#2` for a component's second occurrence, `@C212#2.7140` for a
109
+ composite's second occurrence in its segment; a trailing `+` appends (a time after a date). From the directory the
110
+ writer orders every group as the message specification does; adds a group's trigger segment when it has no mandatory
111
+ data (an empty PCI) and numbers CPS hierarchies; removes a segment that lacks mandatory data, and a group that lacks its
112
+ trigger, with the reason; continues a value too long for its component into the components of the same tag that
113
+ follow (a long name across C080's 3036s, shipping marks across PCI's 7102s); infers a DTM's format (102, 203, 204); and
114
+ writes UNA, UNB, UNH, UNS where the message has one, UNT with the segment count, and UNZ. The interchange and message
115
+ control references are the document's number (its last 14 word characters).
116
+
117
+ **The check is independent.** `sdc_gdr2edifact.check` parses the interchange from its text, by code that shares
118
+ nothing with the writer, and checks the envelope (counts, references), the segment sequence against the message
119
+ specification's segment table, and every segment against its definition; the tests also parse every interchange with
120
+ [pydifact](https://github.com/nerdocs/pydifact) (MIT), which has no D.24A definitions but reads the syntax.
121
+
122
+ ## Tests
123
+
124
+ ```
125
+ pip install -e ".[dev]"
126
+ SDC_EDIFACT_DIRECTORY=/path/to/d24a.zip python -m pytest
127
+ ```
128
+
129
+ Without `SDC_EDIFACT_DIRECTORY`, every test that needs the directory is skipped and says so.
130
+
131
+ Every sample record of the eight models is mapped, checked and parsed; the DESADV is compared with the library's
132
+ writer; Exceptional Values, refused mappings and a tampered interchange are exercised.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sdc-gdr2edifact"
7
+ version = "4.0.0"
8
+ description = "Governed Data Records as conformant UN/EDIFACT D.24A interchanges, through sdc-mapper: one mapping file per model, every value reported."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ authors = [{ name = "Axius SDC, Inc." }]
14
+ keywords = ["sdc", "semantic data charter", "governed data record", "edifact", "un/edifact", "unece", "mapping"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ ]
18
+ dependencies = [
19
+ "sdc-mapper>=4.2,<5", # placements, joins ('=name'), declared cluster order (4.2.0)
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = ["pytest>=8.0", "pyyaml>=6.0", "lxml>=5.0", "pydifact>=0.2"]
24
+
25
+ [project.entry-points."sdc_mapper.targets"]
26
+ edifact = "sdc_gdr2edifact:EDIFACTMapper"
27
+
28
+ [project.urls]
29
+ Repository = "https://github.com/SemanticDataCharter/sdc-gdr2edifact"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
33
+
34
+ [tool.setuptools.package-data]
35
+ sdc_gdr2edifact = ["mappings/*.yaml"]
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,28 @@
1
+ """sdc-gdr2edifact: Governed Data Records as UN/EDIFACT D.24A interchanges, through sdc-mapper.
2
+
3
+ from sdc_mapper import Engine, load_mapping
4
+ from sdc_gdr2edifact import EDIFACTMapper, mapping_path
5
+ mapper = EDIFACTMapper("/path/to/d24a.zip") # the directory as downloaded from UNECE; or $SDC_EDIFACT_DIRECTORY
6
+ result = Engine().map_record(xml, mapper, load_mapping(mapping_path("cacl4njrwanj15g3p3so8t6h")))
7
+
8
+ One mapping file per model, in `mappings/`. Registered with sdc-mapper as the target `edifact`.
9
+ """
10
+ from pathlib import Path
11
+
12
+ __version__ = "4.0.0"
13
+
14
+ MAPPINGS = Path(__file__).with_name("mappings")
15
+
16
+
17
+ def mapping_path(ct_id: str) -> Path:
18
+ """The mapping file this package publishes for a model, by the model's identifier."""
19
+ found = sorted(MAPPINGS.glob(f"*-{ct_id}.yaml"))
20
+ if not found:
21
+ raise FileNotFoundError(f"sdc-gdr2edifact has no mapping for model {ct_id}")
22
+ return found[-1]
23
+
24
+
25
+ from .directory import Directory, DirectoryNotFound # noqa: E402
26
+ from .mapper import EDIFACTMapper # noqa: E402
27
+
28
+ __all__ = ["EDIFACTMapper", "Directory", "DirectoryNotFound", "mapping_path", "MAPPINGS", "__version__"]