pydifact
Pydifact is a library that aims to provide complete support for reading and writing EDIFACT files. These file format, despite being old, is still a standard in many business cases. In Austria e.g., it is used for the transfer of medical reports between medical doctors.
What it is and what it does
Pydifact is a Python port of a PHP EDIFACT library that lets you work with UN/EDIFACT interchange files—a decades-old but still widely used format for business document exchange, particularly in medical, logistics, and trading sectors. It provides three main workflows: parsing interchanges from files or strings into navigable message and segment objects; iterating directly over segments; and constructing new interchanges programmatically from scratch with custom segments.
The library handles the low-level syntax of EDIFACT (delimiters, segment markers, element separators) so you work with structured message objects instead of raw text. It has no external dependencies, installs quickly, and runs on modern Python versions. The codebase is actively maintained but still marked as Alpha, meaning the API may change—a trade-off to be aware of if you are locking this into production workflows.
Use it for:
- Parse incoming EDIFACT purchase orders or invoices from trading partners into Python objects for validation or database import.
- Generate EDIFACT interchanges programmatically to send standardized EDI messages to external systems.
- Extract and transform specific segments from large EDIFACT files for reporting or data migration.
- Build EDI middleware that reads, validates, and re-serializes EDIFACT messages between legacy and modern systems.
- Integrate EDIFACT support into medical or logistics applications that must exchange documents with regulated partners.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pydifact parses and serializes UN/EDIFACT interchange files, allowing you to read EDI messages from files or strings and construct them programmatically.
Yes, if you need to work with EDIFACT files in Python and can tolerate an Alpha-stage API. The library is actively maintained, has no dependencies, installs easily, and solves a real gap in the Python ecosystem. The main caveat is that the API is not yet stable—pin your version and test carefully before upgrading. If you need a production-hardened EDIFACT tool immediately, review the alternatives listed in the documentation first.
Install
pydifact on PyPI
pip
pip install pydifactuv
uv add pydifactpoetry
poetry add pydifactInstalling pydifact
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release; marked Alpha (Development Status 3) so the API may still shift.
License in practice
MIT license permits commercial and private use with minimal restrictions—you may use, modify, and distribute this library freely provided you include the license notice.
Quickstart
from pydifact.segmentcollection import Interchange
interchange = Interchange.from_str(
"UNA:+,? '"
"UNB+UNOC:1+1234+3333+200102:2212+42'"
"UNH+42z42+PAORES:93:1:IA'"
"MSG+1:45'"
"UNT+5+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
for segment in message.segments:
print(f"Segment tag: {segment.tag}")
Requires Python 3.10 or later.
Verify before relying
- Whether the Alpha status API instability poses a risk for production use in your context.
- Performance characteristics when parsing very large EDIFACT files (extended tests exist but results not published).
- Completeness of support for all UN/EDIFACT message types beyond the documented examples.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 126 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 236,781/month — #8,976 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pydifact-0.2.3-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
interchangeInterchange provides data types and interchange…
permissive · top 15,000 on PyPI
pyx12Pyx12 parses, validates, and converts ANSI X12…
permissive · top 15,000 on PyPI
pycolladapycollada reads, writes, and edits COLLADA 3D…
permissive · top 5,000 on PyPI
phpserializeConverts Python objects to and from PHP…
permissive · top 15,000 on PyPI
vobjectParses and serializes iCalendar and vCard…
permissive · top 5,000 on PyPI
avro-python3Serializes and deserializes data in Apache Avro…
permissive · top 5,000 on PyPI
python-oxmsgParses Outlook MSG files to extract email…
permissive · top 5,000 on PyPI
sendsafelyIntegrates SendSafely secure file transfer and…
permissive · top 15,000 on PyPI
sarif-omProvides Python classes implementing the SARIF…
permissive · top 5,000 on PyPI
pydicomPydicom reads, modifies, and writes DICOM…
permissive · top 5,000 on PyPI