# EDI Parser
A standalone Python library for parsing EDI (Electronic Data Interchange) files. Extracted from the excellent [Bots EDI Translator](https://github.com/bots-edi/bots) project, this library provides powerful EDI parsing capabilities without requiring the full Bots infrastructure (web server, database, job queue, etc.).
## Features
- **Multiple EDI Formats**: Support for EDIFACT, X12, CSV, XML, JSON, TRADACOMS, IDOC, and fixed-width formats
- **Comprehensive Grammar Library**: Includes extensive grammar definitions for various EDI message types
- **Full Validation**: Complete field validation, length checking, and structure verification
- **JSON Output**: Parsed EDI messages are returned as JSON-serializable Python dictionaries
- **Zero External Dependencies**: Uses only Python standard library
- **Simple API**: Easy-to-use interface for parsing EDI files or strings
## Installation
```bash
cd edi_parser
pip install -e .
```
Or for development:
```bash
pip install -e ".[dev]"
```
## Quick Start
### Parse EDIFACT Message
```python
import edi_parser
import json
# EDIFACT ORDERS message
edifact_content = """UNB+UNOC:3+SENDER:14+RECEIVER:14+20231020:1430+1'
UNH+1+ORDERS:D:96A:UN'
BGM+220+ORDER123+9'
DTM+137:20231020:102'
NAD+BY+BUYER123::92'
UNS+D'
UNT+6+1'
UNZ+1+1'"""
result = edi_parser.parse_edi(
content=edifact_content,
editype='edifact',
messagetype='ORDERS'
)
if result['success']:
print(json.dumps(result['data'], indent=2))
else:
print("Errors:", result['errors'])
```
### Parse X12 Message
```python
# X12 850 Purchase Order
x12_content = """ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *231020*1430*U*00401*000000001*0*P*>~
GS*PO*SENDER*RECEIVER*20231020*1430*1*X*004010~
ST*850*0001~
BEG*00*SA*PO123456**20231020~
SE*3*0001~
GE*1*1~
IEA*1*000000001~"""
result = edi_parser.parse_edi(
content=x12_content,
editype='x12',
messagetype='850'
)
```
### Parse from File
```python
result = edi_parser.parse_file(
filepath='path/to/invoice.edi',
editype='edifact',
messagetype='INVOIC'
)
```
## Supported Formats
```python
formats = edi_parser.get_supported_formats()
# Returns:
# {
# 'edifact': 'UN/EDIFACT - United Nations Electronic Data Interchange',
# 'x12': 'ANSI X12 - American National Standards Institute X12',
# 'csv': 'CSV - Comma Separated Values',
# 'fixed': 'Fixed-width record format',
# 'xml': 'XML - Extensible Markup Language',
# 'json': 'JSON - JavaScript Object Notation',
# 'tradacoms': 'TRADACOMS - Trading Data Communications Standard',
# 'idoc': 'SAP IDOC - Intermediate Document',
# }
```
## API Reference
### `parse_edi(content, editype, messagetype, charset='utf-8', **options)`
Parse EDI content and return JSON representation.
**Parameters:**
- `content` (str|bytes): EDI file content
- `editype` (str): Type of EDI (e.g., 'edifact', 'x12', 'csv')
- `messagetype` (str): Message type/grammar name (e.g., 'ORDERS', 'INVOIC', '850')
- `charset` (str): Character encoding (default: 'utf-8')
- `**options`: Additional options:
- `debug` (bool): Enable debug logging
- `checkunknownentities` (bool): Check for unknown entities (default: True)
- `continue_on_error` (bool): Continue parsing even with non-fatal errors
**Returns:**
```python
{
'success': bool, # Whether parsing succeeded
'data': dict, # Parsed EDI tree (if success=True)
'errors': list, # List of error messages (if any)
'message_count': int, # Number of messages found
'editype': str, # EDI type
'messagetype': str # Message type
}
```
### `parse_file(filepath, editype, messagetype, **options)`
Parse an EDI file from a file path. Same parameters as `parse_edi()` except `filepath` instead of `content`.
### `node_to_dict(node)`
Convert a Node tree to a dictionary (used internally).
### `get_supported_formats()`
Get list of supported EDI formats with descriptions.
## Output Structure
The parsed EDI data is returned as a nested dictionary:
```python
{
'BOTSID': 'UNH', # Record/segment ID
'field1': 'value1', # Field values
'field2': 'value2',
'_children': [ # Child records (if any)
{
'BOTSID': 'LIN',
'field1': 'value',
# ...
}
]
}
```
## Examples
See the `examples/parse_edi.py` file for complete working examples including:
- Parsing EDIFACT messages
- Parsing X12 messages
- Parsing from files
- Using custom options
- Listing supported formats
Run the examples:
```bash
cd examples
python parse_edi.py
```
## Grammar Files
The library includes comprehensive grammar definitions in the `grammars/` directory:
```
grammars/
├── edifact/
│ ├── D96A/ # EDIFACT Directory D96A
│ ├── D01B/ # EDIFACT Directory D01B
│ └── ...
├── x12/
│ ├── 00401/ # X12 Version 4010
│ ├── 00501/ # X12 Version 5010
│ └── ...
└── ...
```
Each grammar defines:
- **Structure**: The hierarchical structure of segments/records
- **Record Definitions**: Field definitions including type, length, and validation rules
- **Syntax**: Separators, encoding, and format-specific rules
## Development
### Running Tests
```bash
pytest tests/
```
### Code Quality
```bash
# Format code
black edi_parser/
# Lint
pylint edi_parser/
```
## License
This library is extracted from the Bots EDI Translator project and maintains the same GPLv3 license.
## Credits
- **Original Bots Project**: https://github.com/bots-edi/bots
- **Bots Authors**: Many contributors to the Bots EDI Translator project
This library extracts and focuses solely on the EDI parsing functionality from Bots, removing dependencies on Django, databases, and other infrastructure components to create a lightweight, standalone parser.
## Differences from Bots
This library differs from the full Bots installation:
**Removed:**
- Web server and GUI
- Database (SQLite/PostgreSQL)
- Job queue and scheduler
- Communication channels (FTP, SFTP, AS2, etc.)
- Mapping/transformation engine
- Routing and partner management
**Kept:**
- Complete EDI parsing engine
- All grammar files for various EDI formats
- Full validation capabilities
- Error handling and reporting
**Use this library if you:**
- Only need to parse EDI files (not transform or route them)
- Want a lightweight solution without database dependencies
- Need EDI parsing in a larger application
- Want a simple API for EDI to JSON conversion
**Use full Bots if you:**
- Need complete EDI translation workflows
- Require partner management and routing
- Need communication channels for receiving/sending EDI
- Want a complete B2B integration platform
## Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues.
## Support
For issues and questions:
- Open an issue on GitHub
- Refer to original Bots documentation for EDI concepts: http://bots.readthedocs.io/
## Changelog
### 1.0.0 (2025-01-21)
- Initial release
- Extracted from Bots 4.x
- Support for EDIFACT, X12, CSV, XML, JSON, TRADACOMS, IDOC
- Complete grammar library
- JSON output format
- Zero external dependencies
Raw data
{
"_id": null,
"home_page": "https://github.com/yourusername/edi-parser",
"name": "bots-edi-parser",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "edi, edifact, x12, parser, healthcare, 837, 835, claims, remittance",
"author": "Extracted from Bots EDI Translator",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/8b/c1/fe595ad4bc3c200f4ccc3b5854e6630b9cbdef875d867c42ee99acad24e1/bots_edi_parser-1.0.3.tar.gz",
"platform": null,
"description": "# EDI Parser\n\nA standalone Python library for parsing EDI (Electronic Data Interchange) files. Extracted from the excellent [Bots EDI Translator](https://github.com/bots-edi/bots) project, this library provides powerful EDI parsing capabilities without requiring the full Bots infrastructure (web server, database, job queue, etc.).\n\n## Features\n\n- **Multiple EDI Formats**: Support for EDIFACT, X12, CSV, XML, JSON, TRADACOMS, IDOC, and fixed-width formats\n- **Comprehensive Grammar Library**: Includes extensive grammar definitions for various EDI message types\n- **Full Validation**: Complete field validation, length checking, and structure verification\n- **JSON Output**: Parsed EDI messages are returned as JSON-serializable Python dictionaries\n- **Zero External Dependencies**: Uses only Python standard library\n- **Simple API**: Easy-to-use interface for parsing EDI files or strings\n\n## Installation\n\n```bash\ncd edi_parser\npip install -e .\n```\n\nOr for development:\n\n```bash\npip install -e \".[dev]\"\n```\n\n## Quick Start\n\n### Parse EDIFACT Message\n\n```python\nimport edi_parser\nimport json\n\n# EDIFACT ORDERS message\nedifact_content = \"\"\"UNB+UNOC:3+SENDER:14+RECEIVER:14+20231020:1430+1'\nUNH+1+ORDERS:D:96A:UN'\nBGM+220+ORDER123+9'\nDTM+137:20231020:102'\nNAD+BY+BUYER123::92'\nUNS+D'\nUNT+6+1'\nUNZ+1+1'\"\"\"\n\nresult = edi_parser.parse_edi(\n content=edifact_content,\n editype='edifact',\n messagetype='ORDERS'\n)\n\nif result['success']:\n print(json.dumps(result['data'], indent=2))\nelse:\n print(\"Errors:\", result['errors'])\n```\n\n### Parse X12 Message\n\n```python\n# X12 850 Purchase Order\nx12_content = \"\"\"ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *231020*1430*U*00401*000000001*0*P*>~\nGS*PO*SENDER*RECEIVER*20231020*1430*1*X*004010~\nST*850*0001~\nBEG*00*SA*PO123456**20231020~\nSE*3*0001~\nGE*1*1~\nIEA*1*000000001~\"\"\"\n\nresult = edi_parser.parse_edi(\n content=x12_content,\n editype='x12',\n messagetype='850'\n)\n```\n\n### Parse from File\n\n```python\nresult = edi_parser.parse_file(\n filepath='path/to/invoice.edi',\n editype='edifact',\n messagetype='INVOIC'\n)\n```\n\n## Supported Formats\n\n```python\nformats = edi_parser.get_supported_formats()\n\n# Returns:\n# {\n# 'edifact': 'UN/EDIFACT - United Nations Electronic Data Interchange',\n# 'x12': 'ANSI X12 - American National Standards Institute X12',\n# 'csv': 'CSV - Comma Separated Values',\n# 'fixed': 'Fixed-width record format',\n# 'xml': 'XML - Extensible Markup Language',\n# 'json': 'JSON - JavaScript Object Notation',\n# 'tradacoms': 'TRADACOMS - Trading Data Communications Standard',\n# 'idoc': 'SAP IDOC - Intermediate Document',\n# }\n```\n\n## API Reference\n\n### `parse_edi(content, editype, messagetype, charset='utf-8', **options)`\n\nParse EDI content and return JSON representation.\n\n**Parameters:**\n- `content` (str|bytes): EDI file content\n- `editype` (str): Type of EDI (e.g., 'edifact', 'x12', 'csv')\n- `messagetype` (str): Message type/grammar name (e.g., 'ORDERS', 'INVOIC', '850')\n- `charset` (str): Character encoding (default: 'utf-8')\n- `**options`: Additional options:\n - `debug` (bool): Enable debug logging\n - `checkunknownentities` (bool): Check for unknown entities (default: True)\n - `continue_on_error` (bool): Continue parsing even with non-fatal errors\n\n**Returns:**\n```python\n{\n 'success': bool, # Whether parsing succeeded\n 'data': dict, # Parsed EDI tree (if success=True)\n 'errors': list, # List of error messages (if any)\n 'message_count': int, # Number of messages found\n 'editype': str, # EDI type\n 'messagetype': str # Message type\n}\n```\n\n### `parse_file(filepath, editype, messagetype, **options)`\n\nParse an EDI file from a file path. Same parameters as `parse_edi()` except `filepath` instead of `content`.\n\n### `node_to_dict(node)`\n\nConvert a Node tree to a dictionary (used internally).\n\n### `get_supported_formats()`\n\nGet list of supported EDI formats with descriptions.\n\n## Output Structure\n\nThe parsed EDI data is returned as a nested dictionary:\n\n```python\n{\n 'BOTSID': 'UNH', # Record/segment ID\n 'field1': 'value1', # Field values\n 'field2': 'value2',\n '_children': [ # Child records (if any)\n {\n 'BOTSID': 'LIN',\n 'field1': 'value',\n # ...\n }\n ]\n}\n```\n\n## Examples\n\nSee the `examples/parse_edi.py` file for complete working examples including:\n- Parsing EDIFACT messages\n- Parsing X12 messages\n- Parsing from files\n- Using custom options\n- Listing supported formats\n\nRun the examples:\n\n```bash\ncd examples\npython parse_edi.py\n```\n\n## Grammar Files\n\nThe library includes comprehensive grammar definitions in the `grammars/` directory:\n\n```\ngrammars/\n\u251c\u2500\u2500 edifact/\n\u2502 \u251c\u2500\u2500 D96A/ # EDIFACT Directory D96A\n\u2502 \u251c\u2500\u2500 D01B/ # EDIFACT Directory D01B\n\u2502 \u2514\u2500\u2500 ...\n\u251c\u2500\u2500 x12/\n\u2502 \u251c\u2500\u2500 00401/ # X12 Version 4010\n\u2502 \u251c\u2500\u2500 00501/ # X12 Version 5010\n\u2502 \u2514\u2500\u2500 ...\n\u2514\u2500\u2500 ...\n```\n\nEach grammar defines:\n- **Structure**: The hierarchical structure of segments/records\n- **Record Definitions**: Field definitions including type, length, and validation rules\n- **Syntax**: Separators, encoding, and format-specific rules\n\n## Development\n\n### Running Tests\n\n```bash\npytest tests/\n```\n\n### Code Quality\n\n```bash\n# Format code\nblack edi_parser/\n\n# Lint\npylint edi_parser/\n```\n\n## License\n\nThis library is extracted from the Bots EDI Translator project and maintains the same GPLv3 license.\n\n## Credits\n\n- **Original Bots Project**: https://github.com/bots-edi/bots\n- **Bots Authors**: Many contributors to the Bots EDI Translator project\n\nThis library extracts and focuses solely on the EDI parsing functionality from Bots, removing dependencies on Django, databases, and other infrastructure components to create a lightweight, standalone parser.\n\n## Differences from Bots\n\nThis library differs from the full Bots installation:\n\n**Removed:**\n- Web server and GUI\n- Database (SQLite/PostgreSQL)\n- Job queue and scheduler\n- Communication channels (FTP, SFTP, AS2, etc.)\n- Mapping/transformation engine\n- Routing and partner management\n\n**Kept:**\n- Complete EDI parsing engine\n- All grammar files for various EDI formats\n- Full validation capabilities\n- Error handling and reporting\n\n**Use this library if you:**\n- Only need to parse EDI files (not transform or route them)\n- Want a lightweight solution without database dependencies\n- Need EDI parsing in a larger application\n- Want a simple API for EDI to JSON conversion\n\n**Use full Bots if you:**\n- Need complete EDI translation workflows\n- Require partner management and routing\n- Need communication channels for receiving/sending EDI\n- Want a complete B2B integration platform\n\n## Contributing\n\nContributions are welcome! Please feel free to submit pull requests or open issues.\n\n## Support\n\nFor issues and questions:\n- Open an issue on GitHub\n- Refer to original Bots documentation for EDI concepts: http://bots.readthedocs.io/\n\n## Changelog\n\n### 1.0.0 (2025-01-21)\n- Initial release\n- Extracted from Bots 4.x\n- Support for EDIFACT, X12, CSV, XML, JSON, TRADACOMS, IDOC\n- Complete grammar library\n- JSON output format\n- Zero external dependencies\n",
"bugtrack_url": null,
"license": "GPL-3.0",
"summary": "Standalone EDI parser extracted from Bots EDI Translator supporting EDIFACT, X12, and more",
"version": "1.0.3",
"project_urls": {
"Documentation": "https://github.com/yourusername/edi-parser#readme",
"Homepage": "https://github.com/yourusername/edi-parser",
"Issues": "https://github.com/yourusername/edi-parser/issues",
"Repository": "https://github.com/yourusername/edi-parser"
},
"split_keywords": [
"edi",
" edifact",
" x12",
" parser",
" healthcare",
" 837",
" 835",
" claims",
" remittance"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "51460eb902351f1b001acf5f1ad7c502c86282cfb664238c290c6f3a020ec49d",
"md5": "3ec35c58a0ae44d0ed187e5d31dc7753",
"sha256": "014a3e2f60af85a43e59340db5f8a28d6b3d99d283c52e52c915c69c6c3e56df"
},
"downloads": -1,
"filename": "bots_edi_parser-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3ec35c58a0ae44d0ed187e5d31dc7753",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 12176333,
"upload_time": "2025-10-22T00:44:00",
"upload_time_iso_8601": "2025-10-22T00:44:00.420392Z",
"url": "https://files.pythonhosted.org/packages/51/46/0eb902351f1b001acf5f1ad7c502c86282cfb664238c290c6f3a020ec49d/bots_edi_parser-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "8bc1fe595ad4bc3c200f4ccc3b5854e6630b9cbdef875d867c42ee99acad24e1",
"md5": "5bc73e73a4af1f70324d5c3c53090e09",
"sha256": "7747a1b5221f34816ae22b4d7d5833a3a87dde0cb336df473e67bada73fdcf80"
},
"downloads": -1,
"filename": "bots_edi_parser-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "5bc73e73a4af1f70324d5c3c53090e09",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4455455,
"upload_time": "2025-10-22T00:44:03",
"upload_time_iso_8601": "2025-10-22T00:44:03.091089Z",
"url": "https://files.pythonhosted.org/packages/8b/c1/fe595ad4bc3c200f4ccc3b5854e6630b9cbdef875d867c42ee99acad24e1/bots_edi_parser-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-22 00:44:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yourusername",
"github_project": "edi-parser",
"github_not_found": true,
"lcname": "bots-edi-parser"
}