{"id":13592054,"url":"https://github.com/nerdocs/pydifact","last_synced_at":"2025-05-15T08:08:32.673Z","repository":{"id":20745730,"uuid":"90796000","full_name":"nerdocs/pydifact","owner":"nerdocs","description":"A python EDIFACT library.","archived":false,"fork":false,"pushed_at":"2025-02-27T18:21:05.000Z","size":414,"stargazers_count":165,"open_issues_count":7,"forks_count":48,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-03T04:08:49.261Z","etag":null,"topics":["edifact","library","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nerdocs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nerdoc","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"nerdoc","custom":null}},"created_at":"2017-05-09T22:05:30.000Z","updated_at":"2025-04-02T09:02:45.000Z","dependencies_parsed_at":"2022-07-12T15:17:52.117Z","dependency_job_id":"333ca036-9ed9-476e-a72e-360cc86662c0","html_url":"https://github.com/nerdocs/pydifact","commit_stats":{"total_commits":277,"total_committers":18,"mean_commits":15.38888888888889,"dds":0.2057761732851986,"last_synced_commit":"b61d584af98b677ec36d669d483b5c715c9684ce"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdocs%2Fpydifact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdocs%2Fpydifact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdocs%2Fpydifact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nerdocs%2Fpydifact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nerdocs","download_url":"https://codeload.github.com/nerdocs/pydifact/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166865,"owners_count":21058481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["edifact","library","python3"],"created_at":"2024-08-01T16:01:05.294Z","updated_at":"2025-05-15T08:08:32.659Z","avatar_url":"https://github.com/nerdocs.png","language":"Python","funding_links":["https://github.com/sponsors/nerdoc","https://buymeacoffee.com/nerdoc"],"categories":["Libraries"],"sub_categories":["Python"],"readme":"# pydifact\n\nA Python library to parse and serialize UN/EDIFACT interchanges.\n\n## Preamble\n\nThis is a port of [metroplex-systems/edifact](https://github.com/metroplex-systems/edifact) to Python. Thanks here at the start to [Craig Duncan](https://github.com/duncan3dc) for this cool piece of software. Porting was like a breeze due to the high code quality there. All credits for the initial code here go to him, I just did the translation to Python(3), some \"pythonifications\" of the code and little improvements.\n\n### Why another EDIFACT library?\n\nBecause I did not find a decent UN/EDIFACT library for Python, so I decided to port one of the available good PHP libraries to Python. Here is the result.\n\nATM this is a Work In Progress, the API is not stable yet.\nFeel free to help.\n\n## Install\n\nAs usual, use a virtualenv, and install via pip or pipenv:\n\n```bash\npip install pydifact\n```\n\nHowever, it is not stable yet, so the pypi version, including documentation and code examples, could differ from the latest git code. If in doubt, use the git version:\n```bash\ngit clone https://github.com/nerdocs/pydifact.git\ncd pydifact\npip install -e .\n```\n\n\n## Usage\n\nTo read a full Interchange from a file or string, take the `Interchange` class and\niter over the messages and segments:\n\n```python\nfrom pydifact.segmentcollection import Interchange\n\ninterchange = Interchange.from_file(\"./tests/data/wikipedia.edi\")\ninterchange = Interchange.from_str(\n    \"UNA:+,? '\"\n    \"UNB+UNOC:1+1234+3333+200102:2212+42'\"\n    \"UNH+42z42+PAORES:93:1:IA'\"\n    \"MSG+1:45'\"\n    \"IFT+3+XYZCOMPANY AVAILABILITY'\"\n    \"ERC+A7V:1:AMD'\"\n    \"UNT+5+42z42'UNZ+2+42'\"\n)\nfor message in interchange.get_messages():\n    for segment in message.segments:\n        print(f\"Segment tag: {segment.tag}, content: {segment.elements}\")\n```\n\nYou may also want to iterate directly on segments :\n\n```python\nfrom pydifact.segmentcollection import Interchange\n\ninterchange = Interchange.from_str(\n    \"UNA:+,? '\"\n    \"UNB+UNOC:1+1234+3333+200102:2212+42'\"\n    \"UNH+42z42+PAORES:93:1:IA'\"\n    \"MSG+1:45'\"\n    \"IFT+3+XYZCOMPANY AVAILABILITY'\"\n    \"ERC+A7V:1:AMD'\"\n    \"UNT+5+42z42'UNZ+2+42'\"\n)\n\nfor segment in interchange.segments:\n    print(f\"Segment tag: {segment.tags}, content: {segment.elements}\")\n```\n\nOr you can create an EDI interchange on the fly:\n\n```python\nfrom pydifact.segmentcollection import Interchange\nfrom pydifact.segments import Segment\n\ninterchange = Interchange(syntax_identifier=(\"IBMA\",1),\n                          sender=\"MeMyselfAndIrene\",\n                          recipient=\"TheOtherOne\",\n                          control_reference=\"KLuzs7c6\")\ninterchange.add_segment(Segment(\"QTY\", [\"12\", \"3\"]))\n\nprint(interchange.serialize())\n```\n\nTo include or override the Service String Advice segment (`UNA`), just specify it as a regular segment:\n\n```python\ninterchange.add_segment(Segment(\"UNA\", \":+.? '\"))\n```\n\nYou may also want to parse a « raw » segment bunch which is not an interchange:\n\n```python\nfrom pydifact.segmentcollection import RawSegmentCollection\n\ncollection = RawSegmentCollection.from_str(\"UNH+1+ORDERS:D:96A:UN:EAN008'\")\n\nfor segment in collection.segments:\n    print(f\"Segment tag: {segment.tags}, content: {segment.elements}\")\n```\n\n\n## Limitations\n\n- No support of optional functional groups (`UNG`→`UNE`),\n\n## Alternatives\n\nIn python ecosystem:\n\n- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained.\n- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine.\n- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping.\n\n## Development\n\n### Setup\n\nTo develop pydifact, clone the repository and install the dev requirements:\n\n```bash\nmake dev\n# or\n# pip install -e .[dev]\n```\n\nThis installs all the python packages needed for development and testing.\n\n### Code formatting\n\nFormat all python files using [black](https://black.readthedocs.io) before committing.\n\nHappy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs.\nNevertheless, don't forget adding tests for every aspect you add in code.\n\n### Testing\n\npydifact uses [pytest](http://pytest.org) for testing. There is a shortcut in the Makefile for your convenience:\n\n```bash\nmake test\n```\n\nThis is recommended for faster testing.\n\n\nThere are some additional tests to check the performance of parsing huge files - you can include that tests by calling\n\n```bash\nmake test-extended\n```\n\n## Credits\nThe official formats for UN/EDIFAT provided by UN Secretariat are raw text files located [here](http://www.unece.org/tradewelcome/un-centre-for-trade-facilitation-and-e-business-uncefact/outputs/standards/unedifact/directories/download.html) and html (.htm) files located [here](http://www.unece.org/tradewelcome/un-centre-for-trade-facilitation-and-e-business-uncefact/outputs/standards/unedifact/directories/2011-present.html), similarly for service codes as text and html files located at https://www.gefeg.com/jswg/.\n\n\n## License\n\nThis library is licensed under the\n*MIT* license, see the\n[LICENSE file](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerdocs%2Fpydifact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnerdocs%2Fpydifact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnerdocs%2Fpydifact/lists"}