jshrake / healthkit-to-sqlite

Command-line tool to convert Apple HealthKit data to a SQLite database.
Apache License 2.0
8 stars 1 forks source link
datasette healthkit sqlite

healthkit-to-sqlite

ci crates.io Apache 2.0 License: MIT

Command-line tool to convert Apple HealthKit data to a SQLite database.

Getting Started

  1. Open the Health app on your iOS device.
  2. Click your profile icon in the top-right corner.
  3. Click the "Export All Health Data" button.
  4. Share the resulting ZIP archive to your computer.
  5. Run healthkit-to-sqlite on the exported ZIP archive.
# 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.

Example Queries

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'
  );
{
    "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"
    }
}

Datasette

You can use https://datasette.io/ to view and explore the resulting SQLite database file.

datasette healthkit.db
datasette install datasette-geojson-map
datasette install datasette-leaflet-geojson

Decisions

License

This project is licensed under either of

at your option.