Blog Apple Health data

How do you convert Apple Health export.xml to CSV?

By , maker of Health Export and Atoll · Published · Updated

To convert Apple Health export.xml to CSV, stream it with a parser that reads one<Record> at a time and writes a row for each. Loading the whole file does not work: it is hundreds of megabytes, and the one we measured was cut off at 843.0 MiB. A 14-line Python script below does it with the standard library.

What is inside export.zip

An opened zip with a huge XML scroll, a small folder and route-map tiles laid out in front

Unzipping the file from Export All Health Data gives a folder apple_health_export. The main file is export.xml: one <HealthData> element holding every sample as a<Record>, plus <Workout> and <ActivitySummary> elements. Next to it sit export_cda.xml (clinical records), and, if you have them, folders of workout routes as GPX and ECG recordings as CSV.

Each Record carries its data in attributes:

<Record type="HKQuantityTypeIdentifierHeartRate" sourceName="Apple Watch"
        unit="count/min" startDate="2026-11-30 07:12:04 +0100"
        endDate="2026-11-30 07:12:04 +0100" value="58"/>

The script

A code window sending data through a cable into a spreadsheet tile
import csv, sys
import xml.etree.ElementTree as ET

cols = ['type', 'sourceName', 'unit', 'value', 'startDate', 'endDate']
with open('records.csv', 'w', newline='') as f:
    out = csv.writer(f)
    out.writerow(cols)
    try:
        for _, el in ET.iterparse(sys.argv[1]):
            if el.tag == 'Record':
                out.writerow([el.get(c, '') for c in cols])
            el.clear()
    except ET.ParseError as e:
        print('export.xml ends early (cut off?):', e)

Run it as python3 to_csv.py apple_health_export/export.xml. iterparse hands over each element as it closes, and el.clear() frees it, so memory stays flat however big the file is. Thetry keeps every row written before a cut-off end instead of losing the whole run.

To get one CSV per type, open a writer per type value instead of one file. To keep only heart rate, add and el.get('type') == 'HKQuantityTypeIdentifierHeartRate' to the if.

Three things that go wrong

SymptomCauseFix
Parser error near the endHealth app killed mid-export; file lacks </HealthData>Keep rows before the cut, or export from HealthKit with an app
Script uses gigabytes of RAMET.parse() or a DOM parser loads the whole treeUse iterparse and clear()
Excel truncates the CSVOver 1,048,576 rowsSplit by type or year, or use SQLite

Or skip the XML

Health Export reads HealthKit directly and writes CSV, NDJSON, Apple's XML layout and SQLite in one pass, so there is nothing to convert and nothing to cut off. It is free, and itssource is on GitHub. Other apps are compared inHow to export Apple Health data to CSV.

Sources

Every number on this page was read from these pages on December 2, 2026.

  1. Apple Support: Share your data in Health on iPhone
  2. Health Export source code (MIT): export cut at 883,949,568 bytes
  3. Python docs: xml.etree.ElementTree.iterparse
  4. Microsoft: Excel specifications and limits: 1,048,576 rows per worksheet

Questions

How do I open export.xml?

Unzip export.zip; the file is apple_health_export/export.xml. It opens in any text editor, but at hundreds of megabytes Excel and Numbers will not load it. Convert it to CSV with a streaming script or export CSV directly with an app.

Why does Excel fail on export.xml?

The file is one huge document with millions of Record elements. Excel also stops at 1,048,576 rows per sheet, so even a converted heart rate history may need to be split by type or year.

My export.xml does not end with </HealthData>. What now?

The Health app was killed while writing it. A streaming parser still reads every Record before the cut; the types written at the end of the file are missing. An app that reads HealthKit in pages avoids the problem.