HIPAA X12 validator, parser and converter
Project description
Pyx12
Pyx12 is a HIPAA X12 document parser, validator and converter. It reads an ANSI X12 data file and validates it against a representation of the X12 Implementation Guidelines. By default, it creates a 997 response for 4010 and a 999 response for 5010. It can create an HTML representation of the X12 document and can translate to and from an XML representation of the data file.
Usage
As a command line X12 validator
x12valid.exe <filename>
Fixes common X12 structural errors. Can add or remove line breaks. Can fix loop and segment counting.
x12norm.exe --fix --eol <filename>
Code Examples
Iterate over a loop. Alter children. Show changes
src = pyx12.x12context.X12ContextReader(param, errh, fd_in)
for datatree in src.iter_segments('2300'):
# do something with a 2300 claim loop
# we have access to the 2300 loop and all its children
for loop2400 in datatree.select('2400'):
print(loop2400.get_value('SV101'))
# update something
loop2400.set_value('SV102', 'xx')
# delete something
if loop2400.exists('PWK'):
loop2400.delete('PWK')
# iterate over all the child segments
for seg_node in datatree.iterate_segments():
print(seg_node.format())
Install
uv pip install pyx12
Contributing
The most useful contributions are new implementation-guide maps — either upgrading an existing 4010 map to its 5010 counterpart, or adding support for an X12 transaction pyx12 doesn't yet cover. Pyx12's design already handles the engine; the bottleneck is map coverage.
Where the maps live
XML maps live under pyx12/map/, one file per (transaction, version)
pair, named like <transaction>.<version>.<X-number>[.A<n>].xml —
e.g. 834.4010.X095.A1.xml, 837.5010.X222.A1.xml. The index that
pyx12 consults at runtime is pyx12/map/maps.xml; each entry binds a
(vriic, fic[, tspc]) triple to a map filename:
| Name | Abbreviation | X12 Element |
|---|---|---|
| Interchange Control Version Number | ICVN | ISA12 |
| Version / Release / Industry Identifier Code | VRIIC | GS08 |
| Functional Identifier Code | FIC | GS01 |
| Transaction Set Purpose Code (used only for 278) | TSPC | BHT02 |
Converting a 4010 map to 5010
Several 4010 maps don't yet have 5010 siblings — the candidates are
listed in the commented-out block in maps.xml (270/271 eligibility,
276/277 claim status, 277U, 278 services review, 837D dental, 841). To
add one:
-
Get the 5010 implementation guide for the transaction from X12.org or its HIPAA companion guide.
-
Copy the existing 4010 map as a starting point —
cp pyx12/map/270.4010.X092.A1.xml pyx12/map/270.5010.X279.A1.xml(the X-number changes between versions). -
Walk the IG diff and apply structural changes: new loops, new segments, renamed elements, added or removed code values, changed
usageflags, changedmax_use, changedrepeat, changed syntax rules. The 834.4010 ↔ 834.5010 pair is a good reference for the typical scope of changes. -
Update the
<valid_codes>lists from the 5010 code list. Many external-code references (<external>) stay pointed at the same bundled list incodes.xmlbut the lists themselves may need refreshing — see the commit history forcodes.xmlfor the pattern. -
Register the new file under the
<version icvn="00501">block inmaps.xml:<map vriic="005010X279A1" fic="HS" abbr="270">270.5010.X279.A1.xml</map>
-
Add a fixture and a test. Tests live under
pyx12/test/; the simplest pattern is atest_x12n_document.pyentry that runsx12n_documentagainst a sample file from the IG and compares the 997/999 output, or a focusedtest_map_if_load.pyentry that just confirms the map parses cleanly.
Adding a new X12 IG
The same shape applies — pyx12 is HIPAA-focused but the map engine is
transaction-agnostic. Drop a new XML map into pyx12/map/, register it
in maps.xml with the right (icvn, vriic, fic[, tspc]), and you're
in. If the transaction uses code lists that aren't already bundled,
add them under <codeset> blocks in codes.xml and reference them
from your map's <external> elements.
Running the project
# Set up the dev environment
uv sync --extra dev
# Tests
uv run pytest
# Type check
uv run mypy
# Format & sort imports
uv run ruff format pyx12/
uv run ruff check --select I --fix pyx12/
A green pytest and mypy --strict run is required for CI to pass.
PRs welcome via github.com/azoner/pyx12.
Licensing
Pyx12 uses a BSD license. The full license text is included with the source code for the package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyx12-4.0.0rc1.tar.gz.
File metadata
- Download URL: pyx12-4.0.0rc1.tar.gz
- Upload date:
- Size: 538.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f07fe2aaaaf30f67b36a2caff62ba8453752deb91630db21d5bb8f66a0f1d8
|
|
| MD5 |
ace3b3f96f1d9fbaa541346c243e763c
|
|
| BLAKE2b-256 |
40fda0b5f200aa01e23d7841f2a0501bcaafd6529599202c85d132439125edb3
|
Provenance
The following attestation bundles were made for pyx12-4.0.0rc1.tar.gz:
Publisher:
release.yml on azoner/pyx12
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyx12-4.0.0rc1.tar.gz -
Subject digest:
a9f07fe2aaaaf30f67b36a2caff62ba8453752deb91630db21d5bb8f66a0f1d8 - Sigstore transparency entry: 1436226477
- Sigstore integration time:
-
Permalink:
azoner/pyx12@81c813696ac65d0e63c19110d378b6d07add0d46 -
Branch / Tag:
refs/tags/v4.0.0rc1 - Owner: https://github.com/azoner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@81c813696ac65d0e63c19110d378b6d07add0d46 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyx12-4.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: pyx12-4.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 631.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00ab04aa34567fe327259a6b0b009a1145d9adc46ea667a3c2ccf48b6a8b3d9b
|
|
| MD5 |
66c01102f9cb4373b8760e64eb513a46
|
|
| BLAKE2b-256 |
2115e2b505e5a860d031c26139ae38da32c693b3959593d424cde35a83118cc3
|
Provenance
The following attestation bundles were made for pyx12-4.0.0rc1-py3-none-any.whl:
Publisher:
release.yml on azoner/pyx12
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyx12-4.0.0rc1-py3-none-any.whl -
Subject digest:
00ab04aa34567fe327259a6b0b009a1145d9adc46ea667a3c2ccf48b6a8b3d9b - Sigstore transparency entry: 1436226502
- Sigstore integration time:
-
Permalink:
azoner/pyx12@81c813696ac65d0e63c19110d378b6d07add0d46 -
Branch / Tag:
refs/tags/v4.0.0rc1 - Owner: https://github.com/azoner
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@81c813696ac65d0e63c19110d378b6d07add0d46 -
Trigger Event:
push
-
Statement type: