pyx12.x12file

Interface to an X12 data stream.
  • Efficiently handles large files.

  • Tracks end of explicit loops.

  • Tracks segment/line/loop counts.

  • Tracks some transaction specific counters: 837 2400/LX 837 HL tree

Attributes

Classes

X12Base

Base class of X12 Reader and X12 Writer

X12Reader

Read an X12 data file

X12Writer

X12 file and stream writer

Module Contents

class pyx12.x12file.X12Base[source]

Base class of X12 Reader and X12 Writer Common X12 validation

Initialize the X12 file

err_list: list[_ErrTuple][source]
loops: list[_LoopTuple][source]
hl_stack: list[int][source]
gs_count: int[source]
st_count: int[source]
hl_count: int[source]
seg_count: int[source]
cur_line: int[source]
isa_ids: list[str | None][source]
gs_ids: list[str | None][source]
st_ids: list[str | None][source]
lx_count: int[source]
check_837_lx: bool[source]
isa_usage: str | None[source]
seg_term: str | None[source]
ele_term: str | None[source]
subele_term: str | None[source]
repetition_term: str | None[source]
Close()[source]

Complete any outstanding tasks

Return type:

None

pop_errors()[source]

Pop error list :return: List of errors

Return type:

list[_ErrTuple]

get_isa_id()[source]

Get the current ISA identifier

Return type:

string

get_gs_id()[source]

Get the current GS identifier

Return type:

string

get_st_id()[source]

Get the current ST identifier

Return type:

string

get_ls_id()[source]

Get the current LS identifier

Return type:

string

get_seg_count()[source]

Get the current segment count

Return type:

int

get_cur_line()[source]

Get the current line

Return type:

int

get_term()[source]

Get the original terminators

Return type:

tuple(string, string, string, string)

class pyx12.x12file.X12Reader(src_file_obj)[source]

Bases: X12Base

Read an X12 data file

Errors found when reading the segment such as loop counting or ID errors can be retrieved using the pop_errors function

Initialize the file X12 file reader

Parameters:

src_file_obj (string or open file object) – absolute path of source file or an open, readable file object

fd_in: TextIO[source]
need_to_close: bool[source]
raw: pyx12.rawx12file.RawX12File[source]
icvn: str[source]
seg_term[source]
ele_term[source]
subele_term[source]
repetition_term[source]
close()[source]

Close the underlying file if X12Reader opened it itself. Idempotent.

Return type:

None

cleanup()[source]

At EOF, check for missing loop trailers

Return type:

None

pyx12.x12file.X12file[source]
class pyx12.x12file.X12Writer(src_file_obj, seg_term='~', ele_term='*', subele_term='\\', eol='\n', repetition_term='^')[source]

Bases: X12Base

X12 file and stream writer

Initialize the file X12 file writer

Parameters:
  • src_file_obj (string or open file object) – absolute path of source file or an open, readable file object

  • seg_term (str)

  • ele_term (str)

  • subele_term (str)

  • eol (str)

  • repetition_term (str)

fd_out: TextIO[source]
need_to_close: bool[source]
eol: str[source]
seg_term = '~'[source]
ele_term = '*'[source]
subele_term = '\\'[source]
repetition_term = '^'[source]
close()[source]

Flush trailing loops and close the underlying file if X12Writer opened it itself. Idempotent.

Return type:

None

Close()[source]

Backwards-compatible alias for close().

Return type:

None

Write(seg_data)[source]

Write the segment to the stream given current separators

Parameters:

seg_data (L{segment<segment.Segment>}) – Segment data instance

Return type:

None