Command-line tool to convert Apple HealthKit data to a SQLite database.
# You need to install Rust https://rustup.rs/
cargo install healthkit-to-sqlite-cli
healthkit-to-sqlite export.zip sqlite://healthkit.db
Please create an issue for all bugs, feature requests, or feedback.
Here are a few example SQL queries to help you start exploring your HealthKit data:
select
sum(duration) / 60 as total_duration
from
workout
where
(
creationDate between '2022-12-01' and '2022-12-31'
)
and (
workoutActivityType = 'HKWorkoutActivityTypeWalking' or
workoutActivityType = 'HKWorkoutActivityTypeRunning' or
workoutActivityType = 'HKWorkoutActivityTypeHiking'
);
select
sum(
json_extract(
workoutStatistics,
"$.HKQuantityTypeIdentifierDistanceWalkingRunning.sum"
)
) as total_distance_miles
from
workout
where
(
creationDate between '2022-12-01'
and '2022-12-31'
);
workoutStatistics
column looks like:{
"HKQuantityTypeIdentifierActiveEnergyBurned": {
"endDate": "2019-12-27 13:10:51 -0800",
"startDate": "2019-12-27 12:30:15 -0800",
"sum": 135.70199584960938,
"type": "HKQuantityTypeIdentifierActiveEnergyBurned",
"unit": "Cal"
},
"HKQuantityTypeIdentifierBasalEnergyBurned": {
"endDate": "2019-12-27 13:10:51 -0800",
"startDate": "2019-12-27 12:30:15 -0800",
"sum": 67.24250030517578,
"type": "HKQuantityTypeIdentifierBasalEnergyBurned",
"unit": "Cal"
},
"HKQuantityTypeIdentifierDistanceWalkingRunning": {
"endDate": "2019-12-27 13:10:51 -0800",
"startDate": "2019-12-27 12:30:15 -0800",
"sum": 1.4269200563430786,
"type": "HKQuantityTypeIdentifierDistanceWalkingRunning",
"unit": "mi"
}
}
You can use https://datasette.io/ to view and explore the resulting SQLite database file.
datasette healthkit.db
Workout
table on a single map.Workout
table.datasette install datasette-geojson-map
datasette install datasette-leaflet-geojson
Record
, Workout
, and ActivitySummary
elements are currently exported.Record
elements are inserted to a table with a name matching the value of the element's type
attribute.Workout
elements are inserted to a table named "Workout".
workoutEvent
and workoutStatistics
elements are represented as JSON columns.workoutRoute
element is converted to a GeoJSON LineString and stored in a JSON column named "geometry" for easy integration with https://datasette.io/plugins/datasette-geojson-map.ActivitySummary
elements are inserted as rows to a table named "ActivitySummary".Record
elements must have a type
attribute.Workout
elements must have a workoutActivity
attribute.MetadataEntry
elements must have key
and value
attributes.FileReference
elements must have a path
attribute.This project is licensed under either of
at your option.