3

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.

ISA*00* *00* *01*00060902413PRD *ZZ*RT*200401*0044*U*00401*990002521*0*P*|~ 
GS*SH*0060902413B2B*004919486*20200401*0044*990002521*X*004010~ ST*856*990002521~ 
BSN*00*SHPMORSC4983493955*20200331*1647**TS~ 
HL*1**S~ 
REF*8X*ASN~ 
DTM*002*20200331*1647*18~ 
N1*ST*XYZ Ltd*91*WH3PL1LOC1~ 
N3*XYZ Ltd Logistics,4601 Stilwell Street~ 
N4*Kansas City**64120*US*SP*MO~ 
N1*SF*A Computers*91*CM1LOC1~ 
N3*A Computers Rd, 110~ 
N4*Ran**91730*US*SP*CA~ 
HL*2*1*O~ 
REF*79*60Y~ 
REF*DO*MORC493493955~ 
REF*CR*MRS4983493955~ 
HL*3*2*T~ 
MEA*PD*G*1.00*LB~ 
MEA*PD*HT*1.00*IN~ 
MEA*PD*LN*1.00*IN~ 
MEA*PD*WD*1.00*IN~ 
MAN*GM*134015~ 
HL*4*3*P~ 
MAN*GM*136096~ 
HL*5*4*I~ 
LIN*1*VP*1003200-01-R***CH*US~ 
SN1**10*EA**10*EA~ 
REF*P4*MAIN~ 
REF*JB*MAIN~ 
HL*6*2*T~ 
MEA*PD*G*1.00*LB~ 
MEA*PD*HT*1.00*IN~ 
MEA*PD*LN*1.00*IN~ 
MEA*PD*WD*1.00*IN~ 
MAN*GM*134015~ 
HL*7*6*P~ 
MAN*GM*132973~ 
HL*8*7*I~ 
LIN*2*VP*72004985-03-R***CH*US~ 
SN1**10*EA**10*EA~ 
REF*SE*AJ162918473~ 
REF*SE*AJ163222283~ 
REF*SE*AJ173032198~ 
REF*SE*AJ162915706~ 
REF*SE*AJ174446687~ 
REF*SE*AJ163229302~ 
REF*SE*AJ163228027~ 
REF*SE*AJ174450336~ 
REF*SE*AJ162404159~ 
REF*SE*AJ162913903~ 
REF*P4*239326~ 
REF*JB*MAIN~ 
PKG*F****LHR25 :ZI1, 226, PM: tii@, Recipient Contact: tilt7.~
PKG*F****02_0>25600~CTT*8~ 
SE*24069*990002521~ 
GE*1*990002521~ 
IEA*1*990002521~
2ps
  • 15,099
  • 2
  • 27
  • 47
sham sar
  • 45
  • 1
  • 7
  • What do you need to do with the EDI? It's just text, as long as you know the structure. You might consider giving BOTS a try (http://bots.sourceforge.net/en/index.shtml) – Andrew May 05 '21 at 15:09
  • I have to parse and fetch some required elements from each segment based on requirement using python to create some outbound files. – sham sar May 06 '21 at 04:16
  • So the EDI is inbound, and you want to parse it and create a document / data feed outbound? – Andrew May 06 '21 at 16:05
  • Yes. You are correct. It is kind of 3PL transactions usage. ASN EDI(856, 861,940,945,846,947) formats will be used. – sham sar May 07 '21 at 06:11
  • Ok - so some of those documents are inbound, and some will be outbound.The 945 is a response to the 940, for example. So if the 940 is inbound, the 945 is outbound. You are reinventing a wheel here. EDI translators exist for this very purpose to translate data from EDI to a business format and vice versa. – Andrew May 10 '21 at 14:54
  • Yes. For instance, The customer sends EDI 856 for that the response would be EDI 861. For EDI 940 the response would be EDI 945, For EDI 846 the response would be EDI 947. – sham sar May 11 '21 at 11:11
  • Yes, I know how EDI works - how can I help you answer your question? If you want to parse it in Python, you need to find the delimiters (position 106 in the ISA gives you the segment terminator, always). Split the file up by segment first, then by element delimiter. Certain versions, you'll have to look for subelement separators, also defined in the ISA segment. – Andrew May 11 '21 at 21:15
  • Thank you. I want to parse it using python. I don't find any specific library to parse / handle EDI files. I got o know badx12 and pyx12. But i think these aren't comprehensive. IS there any way to handle these inbound and create outbound files is what i am looking for. Thank you once again Andrew. – sham sar May 12 '21 at 04:41

1 Answers1

0

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

Walucas
  • 2,549
  • 1
  • 21
  • 44
Nayak
  • 1
  • 1