A Python library and CLI tool for parsing, validating, and displaying UN/EDIFACT interchanges.
Project description
edifactlib
A Python package for parsing, validating, and inspecting EDIFACT interchanges. It comes both with a CLI tool for inspecting EDIFACT files directly from the terminal, and with a regular Python library for use in code.
Installation
pip install edifactlib
Usage
As a Python library
from edifactlib import Parser, InterchangeResolver
message = """
UNA:+.? '
UNB+UNOC:3+5412345000013:14+4012345000006:14+260704:1200+REF00001'
UNH+1+ORDERS:D:24A:UN'
BGM+220+PO123456+9'
DTM+137:20260704:102'
NAD+BY+5412345000013::9'
NAD+SU+4012345000006::9'
LIN+1++4712345:EN'
QTY+21:100'
LIN+2++4798765:EN'
QTY+21:50'
UNS+S'
UNT+11+1'
UNZ+1+REF00001'
"""
parser = Parser()
interchange = parser.parse(message)
resolver = InterchangeResolver()
resolver.resolve(interchange)
Parser turns the raw EDIFACT message as an Interchange model (segments, data elements, components) and validates it against the corresponding EDIFACT directory by default (pass validate=False to parser.parse(...) to skip validation). InterchangeResolver then enriches the parsed data with the names/descriptions from the directory.
Command line
After installation, the edifact command is available.
Read and inspect an EDIFACT file:
edifact /path/to/message.edi
Alternatively, pass the message directly as a string:
edifact --from-string "UNA:+.? 'UNB+UNOC:3+...'"
The interchange header, contained messages, and functional groups are printed to the console in a formatted view:
Pass --print-json to print the parsed interchange as JSON instead, e.g. for piping into other tools:
edifact /path/to/message.edi --print-json
Supported EDIFACT versions and directories
EDIFACT version
Currently version 2 and 3 are supported. An implementation for version 4 is planned.
Directories
The following directories are currently supported:
D.24AD.23AD.22BD.22AD.21BD.21A
Older directories will follow.
Transparency regarding AI-generated content
This project values transparency about which content was hand-written and which was created with AI assistance:
- Source code under
src/is mainly hand-written. Any AI-generated portions are explicitly marked as such. - Exception: the
testsfolder. Test code is created with AI assistance. - Any AI-generated code within the
testsfolder is marked as such with a corresponding comment in the code. - If a file in the
testsfolder does not contain such a marker comment, its content was written manually. - The README.MD file was mostly generated by AI.
Status
This project is under active development. The API may still change before the first stable release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file edifactlib-0.3.0.tar.gz.
File metadata
- Download URL: edifactlib-0.3.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b534e831b44798e7bfa891f0f3eee57ba696598d1425729bacb8167184d7e2d
|
|
| MD5 |
3ec7c6d6b1e1850f76a1575d53e690d4
|
|
| BLAKE2b-256 |
eb9ce92a054e141bb8d4832f8425bac7c247fd0b519725a1057a0944db3dc1b7
|
File details
Details for the file edifactlib-0.3.0-py3-none-any.whl.
File metadata
- Download URL: edifactlib-0.3.0-py3-none-any.whl
- Upload date:
- Size: 159.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cf0554a9d626ec8d1b557142935b304ae920f29b77de052774d5257babff1c8
|
|
| MD5 |
c69ac5bb47708a0aab12e346952ad224
|
|
| BLAKE2b-256 |
eb8b6908607ee093e42bdf699741bcb7d738de67aff3454e523e495be989e27f
|