---
title: "Convert Apple Health export.xml to CSV | Nexis"
url: https://getnexis.app/blog/apple-health-export-xml-to-csv/
description: "What is inside export.zip, a 14-line Python script that streams export.xml into CSV, and what to do when the export was cut off at 843 MiB."
---

[Blog](https://getnexis.app/blog/) Apple Health data

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

By [Nexis](https://jutsustudio.com/about/), maker of Health Export and Atoll · Published December 2, 2026 · Updated December 2, 2026

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

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

```
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. The`try` 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

| Symptom | Cause | Fix |
| --- | --- | --- |
| Parser error near the end | Health app killed mid-export; file lacks `</HealthData>` | Keep rows before the cut, or export from HealthKit with an app |
| Script uses gigabytes of RAM | `ET.parse()` or a DOM parser loads the whole tree | Use `iterparse` and `clear()` |
| Excel truncates the CSV | Over 1,048,576 rows | Split by type or year, or use SQLite |

## Or skip the XML

[Health Export](https://apps.apple.com/app/id6808153529) 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 its [source is on GitHub](https://github.com/jutsustudio/apple-health-export). Other apps are compared in [How to export Apple Health data to CSV](https://getnexis.app/blog/export-apple-health-data-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](https://support.apple.com/guide/iphone/share-your-health-data-iph5ede58c3d/ios)
2. [Health Export source code (MIT)](https://github.com/jutsustudio/apple-health-export): export cut at 883,949,568 bytes
3. [Python docs: xml.etree.ElementTree.iterparse](https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse)
4. [Microsoft: Excel specifications and limits](https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3): 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.

## Skip the XML

Health Export writes CSV straight from HealthKit, one file per type. Free, MIT source.

 [Get it on the App Store](https://apps.apple.com/app/id6808153529)
