{"id":15722137,"url":"https://github.com/jshrake/healthkit-to-sqlite","last_synced_at":"2025-05-13T03:43:11.174Z","repository":{"id":65146720,"uuid":"583835476","full_name":"jshrake/healthkit-to-sqlite","owner":"jshrake","description":"Command-line tool to convert Apple HealthKit data to a SQLite database.","archived":false,"fork":false,"pushed_at":"2023-01-18T14:20:36.000Z","size":400,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-03T21:03:48.412Z","etag":null,"topics":["datasette","healthkit","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jshrake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-31T05:07:29.000Z","updated_at":"2025-01-19T07:44:57.000Z","dependencies_parsed_at":"2023-02-10T15:31:30.733Z","dependency_job_id":null,"html_url":"https://github.com/jshrake/healthkit-to-sqlite","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshrake%2Fhealthkit-to-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshrake%2Fhealthkit-to-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshrake%2Fhealthkit-to-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshrake%2Fhealthkit-to-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jshrake","download_url":"https://codeload.github.com/jshrake/healthkit-to-sqlite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253870821,"owners_count":21976610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datasette","healthkit","sqlite"],"created_at":"2024-10-03T22:04:18.018Z","updated_at":"2025-05-13T03:43:11.140Z","avatar_url":"https://github.com/jshrake.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# healthkit-to-sqlite\n\n[![ci](https://github.com/jshrake/healthkit-to-sqlite/actions/workflows/ci.yml/badge.svg)](https://github.com/jshrake/healthkit-to-sqlite/actions)\n[![crates.io](https://img.shields.io/crates/v/healthkit-to-sqlite-cli.svg)](https://crates.io/crates/healthkit-to-sqlite-cli)\n[![Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nCommand-line tool to convert Apple HealthKit data to a SQLite database.\n\n## Getting Started\n\n1. Open the [Health](https://www.apple.com/ios/health/) app on your iOS device.\n2. Click your profile icon in the top-right corner.\n3. Click the \"Export All Health Data\" button.\n4. Share the resulting ZIP archive to your computer.\n5. Run healthkit-to-sqlite on the exported ZIP archive.\n\n```bash\n# You need to install Rust https://rustup.rs/\ncargo install healthkit-to-sqlite-cli\nhealthkit-to-sqlite export.zip sqlite://healthkit.db\n```\n\nPlease [create an issue](https://github.com/jshrake/healthkit-to-sqlite/issues/new/choose) for all bugs, feature requests, or feedback.\n\n\n## Example Queries\n\nHere are a few example SQL queries to help you start exploring your HealthKit data:\n\n* Total walking, running, and hiking workout duration in hours for the month of December 2022:\n\n```sql\nselect\n  sum(duration) / 60 as total_duration\nfrom\n  workout\nwhere\n  (\n    creationDate between '2022-12-01' and '2022-12-31'\n  )\n  and (\n    workoutActivityType = 'HKWorkoutActivityTypeWalking' or\n    workoutActivityType = 'HKWorkoutActivityTypeRunning' or\n    workoutActivityType = 'HKWorkoutActivityTypeHiking'\n  );\n```\n\n* Total distance covered in miles across all workouts for the month of December 2022:\n\n```sql\nselect\n  sum(\n    json_extract(\n      workoutStatistics,\n      \"$.HKQuantityTypeIdentifierDistanceWalkingRunning.sum\"\n    )\n  ) as total_distance_miles\nfrom\n  workout\nwhere\n  (\n    creationDate between '2022-12-01'\n    and '2022-12-31'\n  );\n```\n\n* The JSON data in the `workoutStatistics` column looks like:\n\n```json\n{\n    \"HKQuantityTypeIdentifierActiveEnergyBurned\": {\n        \"endDate\": \"2019-12-27 13:10:51 -0800\",\n        \"startDate\": \"2019-12-27 12:30:15 -0800\",\n        \"sum\": 135.70199584960938,\n        \"type\": \"HKQuantityTypeIdentifierActiveEnergyBurned\",\n        \"unit\": \"Cal\"\n    },\n    \"HKQuantityTypeIdentifierBasalEnergyBurned\": {\n        \"endDate\": \"2019-12-27 13:10:51 -0800\",\n        \"startDate\": \"2019-12-27 12:30:15 -0800\",\n        \"sum\": 67.24250030517578,\n        \"type\": \"HKQuantityTypeIdentifierBasalEnergyBurned\",\n        \"unit\": \"Cal\"\n    },\n    \"HKQuantityTypeIdentifierDistanceWalkingRunning\": {\n        \"endDate\": \"2019-12-27 13:10:51 -0800\",\n        \"startDate\": \"2019-12-27 12:30:15 -0800\",\n        \"sum\": 1.4269200563430786,\n        \"type\": \"HKQuantityTypeIdentifierDistanceWalkingRunning\",\n        \"unit\": \"mi\"\n    }\n}\n```\n\n## Datasette\n\nYou can use \u003chttps://datasette.io/\u003e to view and explore the resulting SQLite database file.\n\n```bash\ndatasette healthkit.db\n```\n\n* Install the \u003chttps://datasette.io/plugins/datasette-geojson-map\u003e plugin to visualize all workout routes in the `Workout` table on a single map.\n* Install the \u003chttps://github.com/simonw/datasette-leaflet-geojson\u003e plugin to render an in-row map for each workout route in the `Workout` table.\n\n```bash\ndatasette install datasette-geojson-map\ndatasette install datasette-leaflet-geojson\n```\n\n## Decisions\n\n* Only the `Record`, `Workout`, and `ActivitySummary` elements are currently exported.\n* `Record` elements are inserted to a table with a name matching the value of the element's `type` attribute.\n* `Workout` elements are inserted to a table named \"Workout\".\n  * The descendent `workoutEvent` and `workoutStatistics` elements are represented as JSON columns.\n  * The descendent `workoutRoute` element is converted to a GeoJSON LineString and stored in a JSON column named \"geometry\" for easy integration with \u003chttps://datasette.io/plugins/datasette-geojson-map\u003e.\n* `ActivitySummary` elements are inserted as rows to a table named \"ActivitySummary\".\n* In an attempt to future proof against Apple adding, removing, or changing element attributes, the code only assumes the existence of a limited number of attributes:\n  * `Record` elements must have a `type` attribute.\n  * `Workout` elements must have a `workoutActivity` attribute.\n  * `MetadataEntry` elements must have `key` and `value` attributes.\n  * `FileReference` elements must have a `path` attribute.\n\n## License\n\nThis project is licensed under either of\n\n* Apache License, Version 2.0, ([LICENSE-APACHE](/LICENSE-APACHE) or \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e)\n* MIT license ([LICENSE-MIT](/LICENSE-MIT) or \u003chttps://opensource.org/licenses/MIT\u003e)\n\nat your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjshrake%2Fhealthkit-to-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjshrake%2Fhealthkit-to-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjshrake%2Fhealthkit-to-sqlite/lists"}