GithubHelp home page GithubHelp logo

albmarin / badx12 Goto Github PK

View Code? Open in Web Editor NEW
49.0 8.0 28.0 397 KB

A Python Library for parsing ANSI ASC X12 files.

License: MIT License

Python 99.11% Shell 0.89%
x12 edi parser python library

badx12's Introduction

badX12

PyPi Coverage Build Status License

A Python Library for parsing ANSI ASC X12 files.

Installing

Install and update using pip:

pip install -U badX12

A Simple Example

badX12 can be imported and used within your own project like so.

from badx12 import Parser

parser = Parser()
document = parser.parse_document("path-to-file/file.edi")

badX12 can also be used to parse an edi file into JSON or XML via the command line.

badx12 parse "path-to-edi-file"
badx12 parse "path-to-edi-file" -e XML -o "path-to-output-dir"

By default the parse command will output a JSON file to the current user's Documents\badX12 directory. The -e flag can be used to specify the export format, and the -o flag can be used to specify the output directory.

Features

  • Parse x12 file format into a python object
  • Parse x12 file format into JSON and XML

Links

badx12's People

Contributors

albmarin avatar dependabot-preview[bot] avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

badx12's Issues

Error when running badx12 from command line

  • badX12 version: master branch
  • Python version: 2.7
  • Operating System: Ubuntu 18.04

Description

I tried converting edi files to json via command line, as documented. However, badx12 gave my an error.

What I Did

cd ~/files/badx12
badx12 parse "./1.edi"

Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/badx12", line 7, in <module>
    from badx12.__main__ import cli
  File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/__init__.py", line 4, in <module>
    from .document import EDIDocument
  File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/document.py", line 3, in <module>
    from badx12.utils import Interchange
  File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/utils/__init__.py", line 1, in <module>
    from .element import Element
  File "/home/ubuntu/.local/lib/python2.7/site-packages/badx12/utils/element.py", line 41
    msg=f"Field {self.name} is too short. Found {content_length} characters, expected "
                                                                                      ^
SyntaxError: invalid syntax

if we have multiple segments in a file facing an error

  • badX12 version:master branch
  • Python version:3.7
  • Operating System:windows 10

Description

I am trying to convert an edi data to json data.
the process actually ran for small files.

What I Did

badx12 parse "ARDEN21999716673775ad3node1.edi" -e JSON -o "output"

###What I got.

'''
2019-05-20 12:57:39,242|ERROR|init.py:44|ARDEN21999716673775ad3node1.edi contains the following errors. Issues: ['The Number of Transaction Sets in GE01 value of 2 does not match the parsed count of 1', 'The Number of Transaction Sets in GE01 value of 2 does not match the parsed count of 1', 'The Number of Included Groups in IEA01 value of 1 does not match the parsed count of 2']
'''

cannot import on python 3.10

  • badX12 version: 0.2.2
  • Python version: 3.10
  • Operating System:

Description

 import badx12
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python310\lib\site-packages\badx12\__init__.py", line 6, in <module>
    from .__main__ import cli
  File "C:\Python310\lib\site-packages\badx12\__main__.py", line 10, in <module>
    from .common.click import add_commands
  File "C:\Python310\lib\site-packages\badx12\common\click.py", line 2, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (C:\Python310\lib\collections\__init__.py)

The Iterable abstract class was removed from collections in Python 3.10. See the deprecation note in the 3.9 collections docs. In the section Removed of the 3.10 docs, the item
``
Remove deprecated aliases to Collections Abstract Base Classes from the collections module. (Contributed by Victor Stinner in bpo-37324.)

Errors when the Segment Terminator is a '\n' character

  • badX12 version: '0.2.2'
  • Python version: Python 3.6.8
  • Operating System: Ubuntu

Description

I'm trying to parse an incoming X12 (834) document. The error is an IndexError but the actual issue seems to be that this file is using a newline character as the segment terminator but newlines are stripped in the "_validate_document" method that is run prior to the parsing step.

There seems to be some discussion on weather or not newline characters are valid segment terminators: kputnam/stupidedi#106

I've gotten things working for me by changing the return statement of the _validate_document method from "return document.replace("\n", "").strip()" to "return document" but I'm not sure if that will change things for other use cases.

What I Did

I have a small test script to start understanding how to use the library:

from badx12 import Parser
parser = Parser()
document = parser.parse_document("test_file.834")
  File "t.py", line 4, in <module>
    document = parser.parse_document("test_file.834")
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 37, in parse_document
    self._separate_and_route_segments()
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 101, in _separate_and_route_segments
    self._route_segment_to_parser(segment)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 114, in _route_segment_to_parser
    self._parse_transaction_set_header(segment)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 193, in _parse_transaction_set_header
    self._parse_segment(transaction_header, header_field_list)
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 134, in _parse_segment
    raise e
  File "/usr/local/lib/python3.6/dist-packages/badx12/parser.py", line 129, in _parse_segment
    segment.fields[index].content = value
IndexError: list index out of range

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Parsing error

  • badX12 version: downloaded on Jan18,2021
  • Python version: 3.9
  • Operating System: MacOS Bis Sur V11.1

Description

Trying to convert EDI to JSON format

I get this below error

badx12 parse medline867s_1.prn
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/bin/badx12", line 8, in
sys.exit(cli())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 764, in call
return self.main(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/commands/parse/init.py", line 40, in parse
report = document.validate()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/document.py", line 60, in validate
self.interchange.validate(report)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/utils/interchange.py", line 24, in validate
self._validate_group_count(report)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/badx12/utils/interchange.py", line 48, in _validate_group_count
if int(self.trailer.iea01.content) != len(self.groups):
ValueError: invalid literal for int() with base 10: ''

What I Did

I ran the below command

$ badx12 parse medline867s_1.prn

Any help is really appreciated. Thanks in advance.

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Wondering about making this configuration based.

  • badX12 version:
  • Python version:
  • Operating System:

Description

I am pretty excited about the start here. I having been tasked with working on parsing a different EDI transaction type (417). What I am thinking is some sort of configuration data that can be used to define the segments a transaction type would be looking for.

I am digging through the code and have a few other questions, as well. For example, I do not have ~ for each segment. How do I set this to simply EOL? I have to admit I am pretty green in use of objects in Python, but I am willing to put in some work and energy to make this a more powerful EDI parsing tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.