Parsing API Reference

Import from the top-level package: from ecgdatakit import FileParser, ECGRecord

FileParser

The main entry point. Auto-discovers all available parsers and dispatches files to the correct one based on content sniffing.

from ecgdatakit import FileParser

fp = FileParser()
fp.parsers           # list of discovered Parser subclasses
record = fp.parse("ecg_file.xml")
MethodReturnsDescription
parse(file_path)ECGRecordAuto-detect format and parse the file

Parser (base class)

Abstract base class for all format-specific parsers. Located at ecgdatakit.parsing.parser.Parser.

MethodReturnsDescription
can_parse(file_path, header) staticboolReturn True if this parser handles the file
parse(file_path)ECGRecordParse the file and return a unified record

parse_batch

from ecgdatakit import parse_batch

records = list(parse_batch(file_list, max_workers=4))

Parse multiple files in parallel using ProcessPoolExecutor. Returns an iterator of ECGRecord objects.

Data Models

All models are Python dataclass instances defined in ecgdatakit.models.

ECGRecord

The unified output type returned by every parser.

FieldTypeDescription
patientPatientInfoPatient demographics
recordingRecordingInfoRecording session metadata
deviceDeviceInfoAcquisition device info
filtersFilterSettingsFilter settings applied during acquisition
leadslist[Lead]ECG lead waveforms
interpretationInterpretationMachine or physician interpretation
measurementsGlobalMeasurementsGlobal ECG interval/axis measurements
median_beatslist[Lead]Median/template beats if available
annotationsdict[str, str]Additional key-value annotations
source_formatstrParser identifier
raw_metadatadictOriginal format-specific metadata
MethodReturnsDescription
to_dict(include_samples=True)dictJSON-serialisable dictionary
to_json(include_samples=True, indent=2)strJSON string

PatientInfo

FieldTypeDescription
patient_idstrPatient identifier
first_namestrFirst name
last_namestrLast name
birth_datedatetime | NoneDate of birth
sexstr"M", "F", or "U"
racestrRace/ethnicity
ageint | NoneAge in years
weightfloat | NoneWeight in kg
heightfloat | NoneHeight in cm
medicationslist[str]Current medications
clinical_historystrClinical history notes

RecordingInfo

FieldTypeDescription
datedatetime | NoneRecording start time
end_datedatetime | NoneRecording end time
durationtimedelta | NoneRecording duration
sample_rateintSamples per second (Hz)
adc_gainfloatADC gain factor (default 1.0)
technicianstrTechnician name
referring_physicianstrReferring physician name
roomstrRoom identifier
locationstrFacility/location

DeviceInfo

FieldTypeDescription
manufacturerstrDevice manufacturer
modelstrDevice model name
serial_numberstrDevice serial number
software_versionstrSoftware version
institutionstrInstitution name
departmentstrDepartment name
acquisition_typestrAcquisition type

FilterSettings

FieldTypeDescription
highpassfloat | NoneHighpass cutoff (Hz)
lowpassfloat | NoneLowpass cutoff (Hz)
notchfloat | NoneNotch frequency (Hz)
notch_activebool | NoneWhether notch filter is active
artifact_filterbool | NoneWhether artifact filter is active

Interpretation

FieldTypeDescription
statementslist[str]Interpretation text statements
severitystr"NORMAL", "ABNORMAL", "BORDERLINE"
sourcestr"machine", "overread", "confirmed"
interpreterstrPhysician name (if overread)
interpretation_datedatetime | NoneWhen interpretation was made

GlobalMeasurements

FieldTypeDescription
heart_rateint | NoneHeart rate (bpm)
rr_intervalint | NoneRR interval (ms)
pr_intervalint | NonePR interval (ms)
qrs_durationint | NoneQRS duration (ms)
qt_intervalint | NoneQT interval (ms)
qtc_bazettint | NoneQTc Bazett (ms)
qtc_fridericiaint | NoneQTc Fridericia (ms)
p_axisint | NoneP-wave axis (degrees)
qrs_axisint | NoneQRS axis (degrees)
t_axisint | NoneT-wave axis (degrees)
qrs_countint | NoneTotal QRS count

Lead

FieldTypeDescription
labelstrLead name ("I", "V1", etc.)
samplesNDArray[np.float64]Signal sample values
sample_rateintSamples per second (Hz)
resolutionfloatResolution (nV/unit, default 1.0)
unitsstrSignal units (e.g. "mV")
qualityint | NoneSignal quality indicator
transducerstrTransducer type
prefilteringstrPre-filtering description

Exceptions

All exceptions inherit from ECGDataKitError.

ExceptionWhen Raised
ECGDataKitErrorBase exception for all errors
UnsupportedFormatErrorFile format not recognized
CorruptedFileErrorFile is truncated or structurally invalid
MissingElementErrorRequired element or field is missing
ChecksumErrorChecksum validation failed
from ecgdatakit import FileParser, UnsupportedFormatError

try:
    record = FileParser().parse("unknown.bin")
except UnsupportedFormatError as e:
    print(f"Format not supported: {e}")