Upgrading to 3.0

x12sdk 3.0 makes loops and segments that the implementation guides let repeat into lists, so a file that repeats them is no longer rejected or silently merged. If your code reads only the high-level API (the tables, the accessors such as claims(), matching, generation, the command line or the MCP server), nothing changes. Code that walks the models directly needs updating for the attributes below, usually by adding [0].

Transaction

Attribute

2.x

3.0

5010 837P

Loop2300.loop_2310a

one loop

list (up to 2)

4010 837P

Loop2300.loop_2305, loop_2310a; Loop2320.loop_2330d; Loop2400.loop_2420f, loop_2420g

one loop

list

4010 837I

Loop2300.loop_2305

one loop

list

835

Footer.plb_segment

one segment

list

834

Loop2000.loop_2100e, loop_2100g

one loop

list

834

Loop2310.n3_segment

one segment

list; [] when absent

270

Loop2100C.dtp_segment, Loop2100D.dtp_segment

one segment

list (up to 9); [] when absent

271

Loop2110C / Loop2110D: ls_segment, loop_2120c / loop_2120d, le_segment

three attributes

ls_loop_2120c / ls_loop_2120d: a list of blocks, each holding one LS, its 2120 loops and its LE

276, 277

Loop2000C.loop_2100c

one loop

list (at least 1)

For example, the service provider on a 276:

from x12sdk.generate import generate_276
from x12sdk.io import X12ModelReader

with X12ModelReader(generate_276(seed=1, patients=1)) as reader:
    (inquiry,) = list(reader.models())

provider_level = inquiry.loop_2000a[0].loop_2000b[0].loop_2000c[0]
# 2.x: provider_level.loop_2100c.nm1_segment
print(provider_level.loop_2100c[0].nm1_segment.name_last_or_organization_name)

and the same pattern elsewhere:

claim.loop_2310a.nm1_segment              ->  claim.loop_2310a[0].nm1_segment
footer.plb_segment.adjustment_reason_code_1
                                          ->  footer.plb_segment[0].adjustment_reason_code_1
loop_2110c.loop_2120c[0].nm1_segment      ->  loop_2110c.ls_loop_2120c[0].loop_2120c[0].nm1_segment

Code that builds these models in Python passes lists; a single instance is not wrapped for you. A parsed single occurrence is a one-item list, and the X12 that x12sdk writes is the same as before.

Other changes to know about

  • A malformed file that made a parser fail with a bare KeyError, TypeError, AttributeError or LookupError now raises X12ParseException, which names the segment, the loop and the HL but not the file’s content, and keeps the original error as __cause__.

  • A 276 service line with no TRN before it raises a ValueError naming SVC and TRN. Code that catches only ValidationError will not see it.

  • In a 271, a DTP, REF or MSG placed after LE breaks the segment order and is now reported, instead of being moved before the LS silently.

The changelog has the full list, including the bugs 3.0 fixes.