A simple Python library for parsing HL7 v2.x messages. Provides segment, field, and component-level access to HL7 messages, along with MLLP (Minimal Lower Layer Protocol) client support. Does not handle HL7 FHIR (v4); it is strictly for the pipe-delimited v2.x wire format.
pip install hl7Verified import paths — ran on the pinned version, not inferred.
Parse an HL7 v2.x message and access segments and fields.
Ensure raw messages use \r: raw = raw.replace('\n', '\r') before parsing.Migrate to async: reader, writer = await open_hl7_connection(host, port). The async MLLP functionality is now part of the base `hl7` package and does not require the `[mllp]` extra.
Use the fhir.resources package for FHIR R4/R5 resources.
Use the string accessor message['MSH.9'] for clarity, or remember segment()[n] is 0-indexed.
Check segments first: if message.segments('ZZZ'): ... or wrap in try/except KeyError.