Skip to main content

Apple Health Exporter

This Python 3 module takes a dump of Apple Health data (the export.zip file generated through an Apple Health data export) and saves a subset of fields and records to a feather file. This can then be read by both Python and R.

Getting started

The package can be used either as an executable module, or as an importable library.

First, install from PyPI (preferably in a new virtual environment):

# optional: create virtualenv within directory to avoid polluting system Python
python -m venv .venv
source .venv/bin/activate

pip install apple-health-exporter

This will also install the following dependencies:

Installing Feather in R

If you'd like to do data analysis on the generated data file in R, then you'll need the feather package:

install.packages("feather")

Usage

  1. Export Apple Health data from within the Health app.

click on "user" icon and then on "export health data"

  1. Pick a location (I usually export to Dropbox) and then run the script:
apple-health-exporter ~/Dropbox/export.zip ~/Downloads/data.feather
# alternative method:
python -m apple_health_exporter ~/Dropbox/export.zip ~/Downloads/data.feather

# Specify XML file name in case zip file has been renamed
apple-health-exporter ~/Dropbox/export_renamed.zip ~/Downloads/data.feather --xml_file_name export.zip

The export zip file contains an XML file containing actual data. By default, this name can be inferred from the stem of the zip file name (for example export.zip will contain a file named export.xml). However, if the zip file has been renamed, you may need to explicitly provide the name of the XML file with the --xml_file_name option.

  1. Now you can load the data in either R or Python.

    In R:

    library(feather)
    library(dplyr)
    data <- read_feather("~/Downloads/data.feather")
    data %>% group_by(type) %>% summarize(entries = n())
    
    # A tibble: 28 × 2
                                                type entries
                                              <chr>   <int>
    1     HKQuantityTypeIdentifierActiveEnergyBurned   84742
    2      HKQuantityTypeIdentifierAppleExerciseTime    5997
    3      HKQuantityTypeIdentifierBasalEnergyBurned   52477
    4      HKQuantityTypeIdentifierBodyFatPercentage      44
    5               HKQuantityTypeIdentifierBodyMass      84
    6          HKQuantityTypeIdentifierBodyMassIndex      40
    7         HKQuantityTypeIdentifierDietaryCalcium      84
    8   HKQuantityTypeIdentifierDietaryCarbohydrates      84
    9     HKQuantityTypeIdentifierDietaryCholesterol      84
    10 HKQuantityTypeIdentifierDietaryEnergyConsumed      84
    # ... with 18 more rows
    

    In Python:

    import pandas as pd
    data = pd.read_feather("data.feather")
    data.groupby("type").size()
    
    type
    HKQuantityTypeIdentifierActiveEnergyBurned           84742
    HKQuantityTypeIdentifierAppleExerciseTime             5997
    HKQuantityTypeIdentifierBasalEnergyBurned            52477
    HKQuantityTypeIdentifierBodyFatPercentage               44
    HKQuantityTypeIdentifierBodyMass                        84
    HKQuantityTypeIdentifierBodyMassIndex                   40
    HKQuantityTypeIdentifierDietaryCalcium                  84
    HKQuantityTypeIdentifierDietaryCarbohydrates            84
    HKQuantityTypeIdentifierDietaryCholesterol              84
    HKQuantityTypeIdentifierDietaryEnergyConsumed           84
    HKQuantityTypeIdentifierDietaryFatMonounsaturated       84
    HKQuantityTypeIdentifierDietaryFatPolyunsaturated       84
    HKQuantityTypeIdentifierDietaryFatSaturated             84
    HKQuantityTypeIdentifierDietaryFatTotal                 84
    HKQuantityTypeIdentifierDietaryFiber                    84
    HKQuantityTypeIdentifierDietaryIron                     84
    HKQuantityTypeIdentifierDietaryPotassium                84
    HKQuantityTypeIdentifierDietaryProtein                  84
    HKQuantityTypeIdentifierDietarySodium                   84
    HKQuantityTypeIdentifierDietarySugar                    84
    HKQuantityTypeIdentifierDietaryVitaminC                 84
    HKQuantityTypeIdentifierDistanceCycling                 21
    HKQuantityTypeIdentifierDistanceWalkingRunning       49111
    HKQuantityTypeIdentifierFlightsClimbed                 562
    HKQuantityTypeIdentifierHeartRate                    26502
    HKQuantityTypeIdentifierHeight                          41
    HKQuantityTypeIdentifierLeanBodyMass                    39
    HKQuantityTypeIdentifierStepCount                     8810
    dtype: int64
    

Examples

Some examples using this data export can be found in my apple-health-examples repo.

Contributing

This package uses Poetry for package management.

To build and test the package locally, check out the repo and:

  1. Install Poetry (one-time) using one of the methods on the Installation page.

  2. Install all dependencies (automatically creates a virtual environment):

poetry install
  1. Make changes, and test using the following commands:
# Type checking
poetry run mypy .
# Linting
poetry run flake8 apple_health_exporter/
# Formatting
poetry run black .

Contributors

Thanks to contributors who have helped improve this package!

Metadata

Release files for apple-health-exporter 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apple-health-exporter 1.2.0
File Size Uploaded Provenance Actions
apple_health_exporter-1.2.0.tar.gz 5.4 kB Without provenance Details for apple_health_exporter-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apple-health-exporter 1.2.0
File Interpreter ABI Platform Actions
apple_health_exporter-1.2.0-py3-none-any.whl Python 3 none any Details for apple_health_exporter-1.2.0-py3-none-any.whl

Total release size: 10.9 kB

Release files / apple_health_exporter-1.2.0.tar.gz

Download URL apple_health_exporter-1.2.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9a388f0822cd423111544bc6b4e2fc7d9e73c065409934a333d266cd123fdc0b
BLAKE2b-256 checksum
How to use checksums
35c4f1ba38c92137b39708d5234c6451529ba7fafef0e3a8a6d76dbc0ab93b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.11.0 Darwin/22.1.0

Release files / apple_health_exporter-1.2.0-py3-none-any.whl

Download URL apple_health_exporter-1.2.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcfa3ed99650bb8a70276e7f6760a5a481b744a55bd25184134b02658da25250
BLAKE2b-256 checksum
How to use checksums
c357550d195a92bc51cd4defcd3a5b5070096592eb939e350777171a6b056899
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.11.0 Darwin/22.1.0

Security for apple-health-exporter 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page