Skip to main content

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:

CLI output as a formatted tree

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

CLI output as 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.24A
  • D.23A
  • D.22B
  • D.22A
  • D.21B
  • D.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: docstrings. Docstrings under src/ may be AI-generated and are not individually marked.
  • Exception: the tests folder. Test code is created with AI assistance.
  • Any AI-generated code within the tests folder is marked as such with a corresponding comment in the code.
  • If a file in the tests folder does not contain such a marker comment, its content was written manually.
  • The README.MD file was mostly generated by AI.

Development

Code is formatted with Black (line length 120) and imports are sorted with isort (Black profile). Install the dev dependencies with:

pip install -e ".[dev]"

Then format the code with:

black .
isort .

Status

This project is under active development. The API may still change before the first stable release.

Metadata

Release files for edifactlib 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for edifactlib 0.5.0
File Size Uploaded
edifactlib-0.5.0.tar.gz 1.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for edifactlib 0.5.0
File Interpreter ABI Platform
edifactlib-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / edifactlib-0.5.0.tar.gz

Download URL edifactlib-0.5.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
d499f2c217a246fd38e96347d02e9ee27e69f9fda027a6659443c7adc830856c
BLAKE2b-256 checksum
How to use checksums
b49afcc55b7206cb522c832c98b18255c2752a2caeeba3ebd47d71bb41e92dd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / edifactlib-0.5.0-py3-none-any.whl

Download URL edifactlib-0.5.0-py3-none-any.whl
Size 163.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8093f9ed0a129c698158178a96924ee2292a37017ed12264e215b942dfb59187
BLAKE2b-256 checksum
How to use checksums
b669fa5f885bf4868f2d56251293917757b06f1ee91914d523a659f2c6d861c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page