{"id":134,"library":"hl7","title":"python-hl7 – HL7 v2.x Message Parser","description":"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.","status":"active","version":"0.4.5","language":"python","source_language":"en","source_url":"https://github.com/johnpaulett/python-hl7","tags":["hl7","healthcare","parser","mllp","hl7v2","medical","interoperability","python"],"install":[{"cmd":"pip install hl7","lang":"bash","label":"Python"},{"cmd":"pip install hl7[mllp]","lang":"bash","label":"Python (with MLLP async client/server)"}],"dependencies":[{"reason":"Required for the async MLLP server/client functionality.","package":"aiorun","optional":true}],"imports":[{"wrong":"import hl7","symbol":"hl7","correct":"import hl7"},{"wrong":"import hl7","symbol":"Message","correct":"from hl7 import Message"},{"wrong":"import hl7","symbol":"parse","correct":"from hl7 import parse"}],"quickstart":{"code":"import hl7\n\nraw = 'MSH|^~\\\\&|SND|SND_FAC|RCV|RCV_FAC|20230101120000||ADT^A01|MSG00001|P|2.3\\rPID|||12345^^^MRG||DOE^JOHN||19800101|M\\r'\nmessage = hl7.parse(raw)\n\n# Access fields using segment(field) notation\nprint(message.segment('MSH'))       # Full MSH segment\nprint(message['MSH.9'])              # Message type: ADT^A01\nprint(message['PID.5'])              # Patient name: DOE^JOHN\nprint(message.segment('PID')[5])     # Same: DOE^JOHN","lang":"python","description":"Parse an HL7 v2.x message and access segments and fields."},"warnings":[{"fix":"Ensure raw messages use \\r: raw = raw.replace('\\n', '\\r') before parsing.","message":"HL7 v2.x messages use \\r (carriage return) as the segment separator, NOT \\n. Messages with \\n line endings will not parse correctly.","severity":"gotcha","affected_versions":"all"},{"fix":"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.","message":"The 'mllp' installation extra was removed along with the synchronous MLLPClient class in 0.4.0. MLLP functionality is now async-only and does not require a separate 'mllp' extra. Attempting to install `hl7[mllp]` on versions >= 0.4.0 will result in a warning.","severity":"breaking","affected_versions":">= 0.4.0"},{"fix":"Use the fhir.resources package for FHIR R4/R5 resources.","message":"This library only handles HL7 v2.x pipe-delimited messages. It does NOT support HL7 FHIR (v4 JSON/XML). Use fhir.resources or fhirclient for FHIR.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the string accessor message['MSH.9'] for clarity, or remember segment()[n] is 0-indexed.","message":"Field indexing is 0-based on the segment object but MSH segment counts the field separator as MSH.1, so MSH[1] returns '|' and MSH[9] returns the message type. This 1-off confusion is common.","severity":"gotcha","affected_versions":"all"},{"fix":"Check segments first: if message.segments('ZZZ'): ... or wrap in try/except KeyError.","message":"Accessing a non-existent segment with message.segment('ZZZ') raises KeyError, not returning None.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'access':24 'along':28 'client':35 'compon':22 'component-level':21 'delimit':50 'fhir':41 'field':19 'format':53 'handl':39 'healthcar':55 'hl7':3,4,14,26,40,54 'hl7v2':58 'interoper':60 'layer':33 'level':23 'librari':11 'lower':32 'medic':59 'messag':6,16,27 'minim':31 'mllp':30,57 'pars':13 'parser':7,56 'pipe':49 'pipe-delimit':48 'protocol':34 'provid':17 'python':2,10,61 'python-hl7':1 'segment':18 'simpl':9 'strict':45 'support':36 'v2.x':5,15,51 'v4':42 'wire':52","created_at":"2026-03-18T15:59:55.131985+00:00","updated_at":"2026-04-16T15:34:50.615407+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"0.4.5","cli_name":"","cli_version":null,"type":"library","homepage":"http://python-hl7.readthedocs.org","github":"https://github.com/johnpaulett/python-hl7","docs":null,"changelog":null,"pypi":"https://pypi.org/project/hl7/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","communication"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":"verified"}}