pydifact


Namepydifact JSON
Version 0.1.8 PyPI version JSON
download
home_pageNone
SummaryPydifact 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.
upload_time2024-10-21 11:31:22
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2017-2024 Christian González Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # pydifact

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

## Preamble

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

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

## Install

As usual, use a virtualenv, and install via pip or pipenv:

```bash
pip install pydifact
```

However, 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:
```bash
git clone https://github.com/nerdocs/pydifact.git
cd pydifact
pip install -e .
```


## Usage

To read a full Interchange from a file or string, take the `Interchange` class and
iter over the messages and segments:

```python
from pydifact.segmentcollection import Interchange

interchange = Interchange.from_file("./tests/data/wikipedia.edi")
interchange = Interchange.from_str(
    "UNA:+,? '"
    "UNB+UNOC:1+1234+3333+200102:2212+42'"
    "UNH+42z42+PAORES:93:1:IA'"
    "MSG+1:45'"
    "IFT+3+XYZCOMPANY AVAILABILITY'"
    "ERC+A7V:1:AMD'"
    "UNT+5+42z42'UNZ+2+42'"
)
for message in interchange.get_messages():
    for segment in message.segments:
        print("Segment tag: {}, content: {}".format(segment.tag, segment.elements))
```

You may also want to iterate directly on segments :

```python
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'"
    "IFT+3+XYZCOMPANY AVAILABILITY'"
    "ERC+A7V:1:AMD'"
    "UNT+5+42z42'UNZ+2+42'"
)

for segment in interchange.segments:
    print("Segment tag: {}, content: {}".format(segment.tag, segment.elements))
```

Or you can create an EDI interchange on the fly:

```python
from pydifact.segmentcollection import Interchange
from pydifact.segments import Segment

interchange = Interchange(syntax_identifier=("IBMA",1),
                          sender="MeMyselfAndIrene",
                          recipient="TheOtherOne",
                          control_reference="KLuzs7c6")
interchange.add_segment(Segment("QTY", ["12", "3"]))

print(interchange.serialize())
```

You may also want to parse a « raw » segment bunch which is not an interchange :

```python
from pydifact.segmentcollection import RawSegmentCollection

collection = RawSegmentCollection.from_str("UNH+1+ORDERS:D:96A:UN:EAN008'")

for segment in collection.segments:
    print("Segment tag: {}, content: {}".format(segment.tag, segment.elements))
```


## Limitations

- No support of optional functional groups (`UNG`→`UNE`),

## Alternatives

In python ecosystem:

- [python-edifact](https://github.com/FriedrichK/python-edifact) - simpler, IMHO less cleaner code, less flexible. may be faster though (not tested). Seems unmaintained.
- [bots](https://github.com/bots-edi/bots) - huge, with webinterface (bots-monitor), webserver, bots-engine.
- [edicat](https://github.com/notpeter/edicat) - simple, only for separating lines/segments for CLI-piping.


## Development

### Setup
To develop pydifact, clone the repository and install the dev requirements:

```
pip install -e .[dev]
```

This installs all the python packages needed for development and testing.

### Code formatting

Format all python files using [black](https://black.readthedocs.io) before committing.

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](http://pytest.org) for testing.
Just exec `pytest` within the project folder to execute the unit tests. Make sure you installed the library properly before using `pip install -e .[dev]`.

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

```bash
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](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydifact",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Christian Gonz\u00e1lez <christian.gonzalez@nerdocs.at>",
    "download_url": "https://files.pythonhosted.org/packages/bc/65/23004dcec16ba34d6936b732ad728e9e3d5e2bfed4b46032b13d043dbfc7/pydifact-0.1.8.tar.gz",
    "platform": null,
    "description": "# 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(\"Segment tag: {}, content: {}\".format(segment.tag, 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(\"Segment tag: {}, content: {}\".format(segment.tag, 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\nYou may also want to parse a \u00ab raw \u00bb 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(\"Segment tag: {}, content: {}\".format(segment.tag, segment.elements))\n```\n\n\n## Limitations\n\n- No support of optional functional groups (`UNG`\u2192`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\n## Development\n\n### Setup\nTo develop pydifact, clone the repository and install the dev requirements:\n\n```\npip 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.\nJust exec `pytest` within the project folder to execute the unit tests. Make sure you installed the library properly before using `pip install -e .[dev]`.\n\nThere is one test to check the performance of parsing huge files, named `test_huge_message` - you can skip that test by calling\n\n```bash\npytest --ignore tests/test_huge_message.py\n```\nThis is recommended for fast testing.\n\n\n## License\n\nThis library is licensed under the\n*MIT* license, see the\n[LICENSE file](LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2017-2024 Christian Gonz\u00e1lez  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "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.",
    "version": "0.1.8",
    "project_urls": {
        "Documentation": "https://pydifact.readthedocs.io",
        "Issues": "https://github.com/nerdocs/pydifact/issues",
        "Repository": "https://github.com/nerdocs/pydifact"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50a565643c5876d677f0612bd83d6c32b83b484f3879c4faeed7b590953d20ba",
                "md5": "66865dc4bf879ae7b2f79fdcfb0636f5",
                "sha256": "7f0f25ea8c879f2bce5080dcd6e517f1c0224a2ac1c400a045d5f7e1fcc5a21e"
            },
            "downloads": -1,
            "filename": "pydifact-0.1.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66865dc4bf879ae7b2f79fdcfb0636f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 26965,
            "upload_time": "2024-10-21T11:31:18",
            "upload_time_iso_8601": "2024-10-21T11:31:18.842427Z",
            "url": "https://files.pythonhosted.org/packages/50/a5/65643c5876d677f0612bd83d6c32b83b484f3879c4faeed7b590953d20ba/pydifact-0.1.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc6523004dcec16ba34d6936b732ad728e9e3d5e2bfed4b46032b13d043dbfc7",
                "md5": "a44c8040ac690582eabf3a3c2f45156b",
                "sha256": "5853ce94e6e3983e7b330d7f0860b81be5c2b140b6ae1590d751b0cba5d78cc5"
            },
            "downloads": -1,
            "filename": "pydifact-0.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "a44c8040ac690582eabf3a3c2f45156b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 27381,
            "upload_time": "2024-10-21T11:31:22",
            "upload_time_iso_8601": "2024-10-21T11:31:22.090630Z",
            "url": "https://files.pythonhosted.org/packages/bc/65/23004dcec16ba34d6936b732ad728e9e3d5e2bfed4b46032b13d043dbfc7/pydifact-0.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 11:31:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nerdocs",
    "github_project": "pydifact",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydifact"
}
        
Elapsed time: 0.90384s