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()withfield_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)
Metadata
Release files for bots-edi-parser 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bots_edi_parser-1.1.1.tar.gz | 4.5 MB | Without provenance | Details for bots_edi_parser-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bots_edi_parser-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for bots_edi_parser-1.1.1-py3-none-any.whl |
Total release size: 16.7 MB
Release files / bots_edi_parser-1.1.1.tar.gz
| Download URL | bots_edi_parser-1.1.1.tar.gz |
|---|---|
| Size | 4.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d1b199266a3f210ce0389056bda1c1bbcd7ed73ef88903e1237dded18c59738
|
|
BLAKE2b-256 checksum How to use checksums |
e72719b8fe3d5fc1ffb6da5851f771587212cfbd9a569dd3c3de1a2c29895b00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Release files / bots_edi_parser-1.1.1-py3-none-any.whl
| Download URL | bots_edi_parser-1.1.1-py3-none-any.whl |
|---|---|
| Size | 12.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3216db1219ac47efad1fcd1f0f87d85cba8dea00e9deed8059b8a9cac68ab4e0
|
|
BLAKE2b-256 checksum How to use checksums |
52ef8a877b9ac1d8ae64967d6b21b8750d5651c51f61cf2241266c1624d077de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.0
|
Security for bots-edi-parser 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.