Parsing EDI X12 file using Python

Viewed 3686

I just want to parse the EDI file using python. I am not sure which is the best way to parse this kind of EDI files. OR should I convert this EDI to other formats and then do parsing? I am not sure. Please help me out. Thanks in advance.

The sample EDI X12 file is as follows.

ISA00 00 0100060902413PRD ZZRT2004010044U004019900025210P|~ GSSH0060902413B2B004919486202004010044990002521X004010~ ST856990002521~ BSN00SHPMORSC4983493955202003311647TS~ HL*1S~ REF8XASN~ DTM00220200331164718~ N1STXYZ Ltd91WH3PL1LOC1~ N3XYZ Ltd Logistics,4601 Stilwell Street~ N4Kansas City64120USSPMO~ N1SFA Computers91CM1LOC1~ N3A Computers Rd, 110~ N4*Ran91730USSPCA~ HL21O~ REF7960Y~ REFDOMORC493493955~ REFCRMRS4983493955~ HL32T~ MEAPDG1.00LB~ MEAPDHT1.00IN~ MEAPDLN1.00IN~ MEAPDWD1.00IN~ MANGM134015~ HL43P~ MANGM136096~ HL54I~ LIN1VP1003200-01-RCHUS~ SN110EA**10EA~ REFP4MAIN~ REFJBMAIN~ HL62T~ MEAPDG1.00LB~ MEAPDHT1.00IN~ MEAPDLN1.00IN~ MEAPDWD1.00IN~ MANGM134015~ HL76P~ MANGM132973~ HL87I~ LIN2VP72004985-03-RCHUS~ SN110EA**10EA~ REFSEAJ162918473~ REFSEAJ163222283~ REFSEAJ173032198~ REFSEAJ162915706~ REFSEAJ174446687~ REFSEAJ163229302~ REFSEAJ163228027~ REFSEAJ174450336~ REFSEAJ162404159~ REFSEAJ162913903~ REFP4239326~ REFJBMAIN~ PKGF**LHR25 :ZI1, 226, PM: tii@, Recipient Contact: tilt7.~ PKGF**02_0>25600~CTT8~ SE24069990002521~ GE1990002521~ IEA1*990002521~

1 Answers

As i am able to see you want to parse X12 856 TRANSACTION set first you need to decide you want to parse in another EDI format or any other CSV/XML format.

As per my experience in Python parsing i was using lightweight parser package in our python directory.

we followed below steps.

1-Installtion of binary python package for EDI 835 PARSER.(pip install edi-835-parser)

2-We used parse function for running the binary package

3-Then we parsed the function on a directory path.

path = '~/Desktop/my_directory_of_edi_files'
transaction_sets = parse(path)

4-Then we import the parser function as per our folder directory for Middleware integration tool.

from edi_835_parser import parse

path = '~/etc/my_directory_of_edi_files'
transaction_sets = parse(full directory path destination)

data = transaction_sets.to_dataframe()

5-And then save that pd.DataFrame as a .csv/xml file.

6-Test the package and parser after above.

This we followed not sure this helps your queries or not but you can explore binary parser package for Python EDI set, this might helpful.

thanks

Related