Skip to main content

Standalone EDI parser extracted from Bots EDI Translator supporting EDIFACT, X12, and more

Project description

EDI Parser

Standalone EDI parsing library extracted from Bots EDI Translator. Supports X12, EDIFACT, CSV, XML, JSON, TRADACOMS, IDOC and more.

Installation

pip install -e .

Quick Start

Using the Demo CLI

# List available test files
python3 demo.py list 835
python3 demo.py list 837

# Validate a single file
python3 demo.py validate 835 test_files/835/835-all-fields.dat

# Parse a single file (lenient mode)
python3 demo.py parse 837 test_files/837/commercial.dat --lenient

# Run all files in a directory
python3 demo.py validate-all 835
python3 demo.py parse-all 837 --lenient

# Verbose mode (shows function entry/exit logging)
python3 demo.py --verbose validate 835 test_files/835/835-denial.dat

Using the Python API

import edi_parser

# Validate a file (strict)
result = edi_parser.validate_file(
    filepath='payment.835',
    editype='x12',
    messagetype='835005010'
)

if result['valid']:
    print("✓ Valid")
else:
    print(f"✗ {result['error_count']} errors")
    for error in result['errors']:
        print(f"  - {error['description']}")

# Parse a file (lenient - best effort)
result = edi_parser.parse_file(
    filepath='payment.835',
    editype='x12',
    messagetype='835005010',
    field_validation_mode='lenient',
    continue_on_error=True
)

if result['success']:
    data = result['data']  # Extracted EDI data

Two Modes

1. Validation (Strict)

  • Returns ALL errors with descriptions and suggestions
  • Use before sending files to trading partners
  • Function: validate_file()

2. Parsing (Lenient)

  • Extracts data even from imperfect files
  • Best-effort parsing for data extraction
  • Function: parse_file() with field_validation_mode='lenient'

Project Structure

edi_parser/
├── demo.py                      # Simple CLI demo
├── test_files/                  # Real-world test samples
│   ├── 835/                     # 7 EDI 835 test files
│   │   ├── 835-all-fields.dat
│   │   ├── 835-denial.dat
│   │   └── ...
│   └── 837/                     # 16 EDI 837 test files
│       ├── 837D-all-fields.dat
│       ├── 837I-all-fields.dat
│       ├── 837P-all-fields.dat
│       ├── commercial.dat
│       └── ...
├── edi_parser/                  # Source code
│   ├── api.py                   # Main API
│   ├── core/                    # Core parsing engine
│   ├── lib/
│   │   ├── utils.py
│   │   └── logging_utils.py     # Function logging utilities
│   ├── grammars/                # Transaction grammars
│   │   └── x12/
│   │       └── 5010/
│   │           ├── 835005010.py
│   │           └── 837005010.py
│   └── transformers/            # Data transformers
└── implementation_guides/       # XML implementation guides
    └── *.xml

Test Files

The test files in test_files/835/ and test_files/837/ are sourced from the Healthcare Data Insight API Examples repository and represent real-world EDI scenarios:

835 Test Files (7 files):

  • Payment/remittance advice scenarios
  • Denials, provider adjustments, negotiated discounts
  • Various adjustment reason codes

837 Test Files (16 files):

  • Professional (837P), Institutional (837I), and Dental (837D) claims
  • Specialized scenarios: ambulance, anesthesia, chiropractic, wheelchair
  • Coordination of Benefits (COB), commercial insurance, PPO repricing

Note: The grammars now support full X12 interchange envelopes (ISA/GS/ST/SE/GE/IEA). Some test files may be malformed (missing GS/GE segments) and will fail validation, but properly formatted files with complete envelopes parse successfully.

Logging

The parser uses Python's logging module (no print statements).

Normal mode (INFO):

import edi_parser
result = edi_parser.parse_file(...)
# Shows: INFO, WARNING, ERROR

Verbose mode (DEBUG):

python3 demo.py --verbose validate 835 test_files/835_sample.edi
# Shows: Function entry/exit, detailed flow

Programmatic:

import logging
logging.basicConfig(level=logging.DEBUG)
# or
from edi_parser.lib.logging_utils import enable_verbose_logging
enable_verbose_logging()

Supported Transactions

Common X12 healthcare transactions:

  • 835 - Health Care Claim Payment/Advice
  • 837 - Health Care Claim (Professional, Institutional, Dental)
  • 270/271 - Eligibility Inquiry/Response
  • 276/277 - Claim Status Inquiry/Response
  • 834 - Benefit Enrollment
  • And many more...

Development

Grammar Development

Hand-rolled grammars are preferred over auto-generated:

# Generate draft from XML (reference only)
python3 ../x12xml_to_bots_grammar.py \
    implementation_guides/835.5010.X221.A1.xml \
    835_draft.py

# Then hand-edit for simplicity and permissiveness
# Use existing grammars in grammars/x12/5010/ as templates

See x12xml_to_bots_grammar.py header for full SOP.

Adding Function Logging

from edi_parser.lib.logging_utils import log_function_call

@log_function_call
def my_function(x, y):
    return x + y

# In DEBUG mode, this logs:
#   → Entering my_function
#   ← Exiting my_function

Or use metaclass for entire classes:

from edi_parser.lib.logging_utils import LoggedMeta

class MyClass(metaclass=LoggedMeta):
    def my_method(self):
        pass  # Automatically logged in DEBUG mode

Philosophy

  • Minimal - No bloat, no unnecessary files
  • Radical Simplicity - One demo, one README, two test files
  • Functional - Full parsing capability without compromise
  • Proper Logging - No print statements, structured logging with levels
  • Real-World - Handles imperfect files with lenient mode

License

Based on Bots EDI Translator (GNU GPL v3)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bots_edi_parser-1.1.0.tar.gz (4.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bots_edi_parser-1.1.0-py3-none-any.whl (12.2 MB view details)

Uploaded Python 3

File details

Details for the file bots_edi_parser-1.1.0.tar.gz.

File metadata

  • Download URL: bots_edi_parser-1.1.0.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for bots_edi_parser-1.1.0.tar.gz
Algorithm Hash digest
SHA256 634e10f9c18a9c589df596edce096d7902a5df1d8267703b613a7d71e9ebb742
MD5 dc8e1127a16185a480896eb1be6b8a82
BLAKE2b-256 ce1200cfc2274a0d1ee51114ce43fe9c0bdbe8d55f1998400bd05321006f4cea

See more details on using hashes here.

File details

Details for the file bots_edi_parser-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bots_edi_parser-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a00e9801cf748610a2f13b3b236a376a1eb17e33bdf0e01c58ab491aca5cfa4
MD5 2c03feec582e598d57cc0aceb3ae323f
BLAKE2b-256 90213633944b1d41e45313f12ac28dad26b3436393f9509d7a9194898a58bdbb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page