项目作者: willingham

项目描述 :
Utilities for generating and validating x12 EDI
高级语言: Python
项目地址: git://github.com/willingham/x12-utils.git
创建时间: 2019-04-21T01:53:04Z
项目社区:https://github.com/willingham/x12-utils

开源协议:

下载


X12 Utils

Lightweight utilities for working with x12 EDI

Background & Purpose

Around 2010, I started working with EDI in a limited capacity. At the time, I had no clue what it was, and didn’t seem to find too much free help on the internet. So, after spending countless hours digging through vendor-specific companion guides and comparing them to previously generated EDI, I was finally able to understand what was going on.

I’ve been writing Python packages to generate EDI for various organizations since around 2013. In those projects I have used string concatenatiion, Jinja templating, Django templating, and a few more methods to generate EDI. After much trial and error, I landed on a method to generate the EDI that was easy to maintain. That is the x12_generator included in this repository.

Since there is another crucial step, validating the resulting EDI, I have also included the x12_validator module which is a lightweight wrapper around the great work done on pyx12 by @azoner.

Installation

  1. pip install x12-utils

Included Utilities

Generator

The x12_generator is a small helper for generating syntactically correct x12 EDI, however, does not assist in ensuring correct structure at all.

Usage

  1. from x12_utils.x12_generator import x12_generate
  2. generator_input = [
  3. ("ISA", ["00", " ", "00", " ", "ZZ"]),
  4. ("GS", ["BE", " ", "00", " ", "ZZ"]),
  5. ("ST", ["00", " ", "00", " ", "ZZ"]),
  6. ("SE", ["00", " ", "00", " ", "ZZ"]),
  7. ("GE", ["00", " ", "00", " ", "ZZ"]),
  8. ("IEA", ["00", " ", "00", " ", "ZZ"]),
  9. ]
  10. edi = x12_generate(src=generator_input)
  11. # `edi` will look like:
  12. # ISA*00* *00* *ZZ~
  13. # GS*BE* *00* *ZZ~
  14. # ST*00* *00* *ZZ~
  15. # SE*00* *00* *ZZ~
  16. # GE*00* *00* *ZZ~
  17. # IEA*00* *00* *ZZ~
  18. #
  19. # Note: This is not structurally valid EDI, just an example to show the format.

Validator

The x12_validator is a light wrapper around @azoner’s pyx12 intended for use in other projects.

Usage

  1. from x12_utils.x12_validator import x12_validate
  2. result = x12_validate(
  3. src=edi, # String or file-like object
  4. params=None, # Valid [pyx12](https://github.com/azoner/pyx12) params or None
  5. generate_html=False, # Passed to [pyx12](https://github.com/azoner/pyx12)
  6. generate_997=False, # Passed to [pyx12](https://github.com/azoner/pyx12)
  7. generate_xml=False, # Passed to [pyx12](https://github.com/azoner/pyx12)
  8. )
  9. # Assuming valid EDI, `result` will look like
  10. # {
  11. # "997": "",
  12. # "errors": "",
  13. # "html": "",
  14. # "ok": True,
  15. # "xml": ""
  16. # }

Documentation

Just read the code. The docstrings explain it.