Package: apple-health-exporter
Apple Health ExporterThis Python 3 module takes a dump of Apple Health data (theexport.zipfile
generated through an Apple Health data export) and saves a subset of fields and
records to afeatherfile. This can then be
read by both Python and R.Getting startedThe 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 Pythonpython-mvenv.venvsource.venv/bin/activate

pipinstallapple-health-exporterThis will also install the following dependencies:pandaspyarrowlxmlInstalling Feather in RIf you'd like to do data analysis on the generated data file in R, then you'll
need the feather package:install.packages("feather")UsageExport Apple Health data from within the Health app.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-mapple_health_exporter~/Dropbox/export.zip~/Downloads/data.feather# Specify XML file name in case zip file has been renamedapple-health-exporter~/Dropbox/export_renamed.zip~/Downloads/data.feather--xml_file_nameexport.zipThe 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 exampleexport.zipwill contain a file namedexport.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_nameoption.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 rowsIn Python:importpandasaspddata=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: int64ExamplesSome examples using this data export can be found in myapple-health-examplesrepo.ContributingThis package usesPoetryfor package management.To build and test the package locally, check out the repo and:Install Poetry (one-time) using one of the methods on theInstallationpage.Install all dependencies (automatically creates a virtual environment):poetry installMake changes, and test using the following commands:# Type checkingpoetryrunmypy.# Lintingpoetryrunflake8apple_health_exporter/# Formattingpoetryrunblack.ContributorsThanks to contributors who have helped improve this package!@aapris@brunoamaral@Jeanselme