Skip to main content

A Python EDI file parser.

Project description

pydifact

A Python library to parse and serialize UN/EDIFACT messages.

Preamble

This is a port of metroplex-systems/edifact to Python. Thanks here at the start to Craig Duncan 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.

Why another EDIFACT library?

Because 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.

ATM this is a Work In Progress, the API is not stable yet. Feel free to help.

Usage

To read a message from a file or from a string, take the Message class and iter over the segments:

from pydifact.message import Message
message = Message.from_file("./tests/data/order.edi")
message = Message.from_str("UNA:+,? 'UNH+1+ORDERS:D:96A:UN:EAN008'")

for segment in message.segments:
    print('Segment tag: {}, content: {}'.format(
        segment.tag, segment.elements))

Or you can create an EDI message:

from pydifact.message import Message
from pydifact.segments import Segment
message = Message()
message.add_segment(Segment('QTY', ['12', '3']))
print(message.serialize())

Development

To develop pydifact, install the dev requirements with pipenv install --dev. This installs all python packages needed for development and testing.

Format all python files using black.

Happy coding, PR are more than welcome to make this library better, or to add a feature that matches your needs. Nevertheless, don't forget adding tests for every aspect you add in code.

Testing

pydifact uses pytest for testing. Just exec pytest within the project folder to execute the unit tests.

There is one test to check the performance of parsing huge files, named test_huge_message - you can skip that test by calling

pytest --ignore tests/test_huge_message.py

This is recommended for fast testing.

License

This library is licensed under the MIT license, see the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydifact-0.0.5.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

pydifact-0.0.5-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file pydifact-0.0.5.tar.gz.

File metadata

  • Download URL: pydifact-0.0.5.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for pydifact-0.0.5.tar.gz
Algorithm Hash digest
SHA256 b8c26a95399669dd63b62e6d0d522d51388dafcfaa42e938ccae149ceee460d2
MD5 21e2feb0d14cfb49dcd2a4f16168b554
BLAKE2b-256 a31e47dfdc079835d9028dbfa5052994ddb537d571388e847863dd257b685ee5

See more details on using hashes here.

Provenance

File details

Details for the file pydifact-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pydifact-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for pydifact-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a884e830aa028fe4d0469928e4d5e10006c5e1b1f79c86cec7f6c061f85f6edf
MD5 be7c25e6e03999c8577756b9142c9b49
BLAKE2b-256 410910f1003aa32a4014ccbaf6d2d8198971266877b03c4d8c5759f18b470bfa

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page