{"id":14841,"library":"pyx12","title":"PyX12 - HIPAA X12 Parser and Validator","description":"PyX12 is a Python library for validating, parsing, and converting HIPAA X12 EDI (Electronic Data Interchange) files. It supports various transaction sets and versions, primarily focusing on compliance and structural integrity. The current stable version on PyPI is 2.3.3. A bugfix release 2.3.4 is available on GitHub, and a Python 3-only version 3.0.0 is currently in release candidate phase, which will enforce Python 3.6+.","status":"active","version":"2.3.3","language":"en","source_language":"en","source_url":"http://github.com/azoner/pyx12","tags":["x12","edi","hipaa","healthcare","parser","validator","transaction-sets"],"install":[{"cmd":"pip install pyx12","lang":"bash","label":"Install PyX12"},{"cmd":"pip install pyx12[xml]","lang":"bash","label":"Install with XML support"}],"dependencies":[{"reason":"Required for XML output features (e.g., converting X12 to XML).","package":"lxml","optional":true},{"reason":"Used on Linux for file extended attributes, optional for core functionality.","package":"python-xattr","optional":true}],"imports":[{"symbol":"X12Message","correct":"from pyx12.x12message import X12Message"},{"note":"X12N is used for walking and validating HIPAA transaction sets.","symbol":"X12N","correct":"from pyx12.map_walker import X12N"}],"quickstart":{"code":"import os\nfrom pyx12.x12message import X12Message\nfrom pyx12.map_walker import X12N\n\n# Create a dummy X12 file for demonstration\nedi_data = \"\"\"ISA*00*          *00*          *ZZ*SENDERID       *ZZ*RECEIVERID     *200101*1200*U*00401*000000001*0*T*:~GS*HI*SENDER*RECEIVER*20010101*1200*1*X*004010VICS~ST*837*0001*005010X222~BHT*0019*00*01*20010101*1200*CH~HL*1**20*1~PRV*BI*PXC*01~NM1*85*1*SMITH*JOHN*P***XX*1234567890~PER*IC*JOHN SMITH*TE*5555551212~SE*10*0001~GE*1*1~IEA*1*000000001~\"\"\"\n\n# Save the EDI data to a temporary file\nfile_path = \"test_837.edi\"\nwith open(file_path, \"w\") as f:\n    f.write(edi_data)\n\n# Initialize X12Message with the file\ntry:\n    # Using a dummy map_path for basic parsing, real validation requires actual maps\n    # For a full validation, set X12_MAP_PATH_INI or pass map_path parameter\n    # Example: map_path = os.environ.get('X12_MAP_PATH', './maps')\n    msg = X12Message(file_path)\n\n    # Iterate through segments\n    print(\"\\n--- Segments --- \")\n    for segment in msg.walk_segments():\n        print(f\"Segment: {segment.get_tag()}, Elements: {segment.get_elements()}\")\n\n    # Perform basic validation (requires map files to be configured or provided)\n    print(\"\\n--- Validation (requires map files) ---\")\n    # Note: For this quickstart, actual validation will likely fail without proper map setup.\n    # Configure map paths via environment variable or 'map_path' parameter in X12N.\n    # os.environ['X12_MAP_PATH'] = 'path/to/your/map/files'\n    walker = X12N(msg)\n    # validation_result = walker.validate()\n    # print(f\"Validation Result: {validation_result.get_state()}\")\n    print(\"Note: Full validation requires X12 map files. See documentation for setup.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(file_path):\n        os.remove(file_path)\n","lang":"python","description":"This quickstart demonstrates how to parse an X12 EDI file using `X12Message` and iterate through its segments. It also shows the basic setup for `X12N` for validation, though full validation requires proper configuration of X12 map files (schemas) which are not included in the basic installation."},"warnings":[{"fix":"Ensure your environment uses Python 3.6 or newer for PyX12 v3.x. For Python 2.x compatibility, use PyX12 v2.x.","message":"PyX12 version 3.0.0 and later are Python 3.6+ exclusive. Attempting to run v3.x code with Python 2.x will result in `SyntaxError` or other runtime failures.","severity":"breaking","affected_versions":"3.0.0+"},{"fix":"Download appropriate X12 map files (e.g., from external sources or provided by your trading partner) and configure their location using the `X12_MAP_PATH` environment variable or by passing the `map_path` argument to `X12Message` or `X12N`.","message":"Effective validation of X12 messages requires the correct X12 map (schema) files. These files are not shipped with the `pyx12` library and must be sourced and configured separately (e.g., via the `X12_MAP_PATH` environment variable or `map_path` parameter).","severity":"gotcha","affected_versions":"All"},{"fix":"Implement custom parsing logic on top of the `X12Message` and `X12N` classes to extract specific fields and loop data into your desired Python data structures.","message":"PyX12 provides low-level access to segments and elements. Extracting data into a simple Python dictionary or object structure for specific transaction sets often requires manual traversal and mapping logic, which is not automatically provided by the core library.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pyx12` to install the library.","cause":"The `pyx12` package is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'pyx12'"},{"fix":"Ensure X12 map files are available and their directory is correctly specified via the `X12_MAP_PATH` environment variable or the `map_path` parameter when initializing `X12Message` or `X12N`.","cause":"The library could not locate the necessary X12 map (schema) file for the transaction set and version being processed, or the configured `X12_MAP_PATH` is incorrect.","error":"pyx12.errors.X12MapNotFoundException: Can not find map file for ..."},{"fix":"If using PyX12 v3.x, ensure you are running Python 3.6+. If you require Python 2.x compatibility, you must use PyX12 v2.x and its corresponding syntax.","cause":"You are attempting to run PyX12 v3.x (Python 3 only) code in a Python 2.x environment, or vice-versa with v2.x on Python 3 (less common).","error":"SyntaxError: invalid syntax (on line ...)"}],"ecosystem":"pypi"}