#sqlite #command-line-tool #apple #convert #health-kit #datasette

app healthkit-to-sqlite-cli

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

4 releases

0.0.4 Dec 31, 2022
0.0.3 Dec 31, 2022
0.0.2 Dec 31, 2022
0.0.1 Dec 31, 2022

#996 in Database interfaces

MIT/Apache

340KB
756 lines

healthkit-to-sqlite

ci crates.io Apache 2.0 License: MIT

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

workout-routes-examples

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 the healthkit-to-sqlite tool on the exported ZIP archive.
cargo install healthkit-to-sqlite-cli
healthkit-to-sqlite export.zip sqlite://healthkit.db

Datasette

You can use https://datasette.io/ to view and explore the resulting SQLite database file. Install the https://datasette.io/plugins/datasette-geojson-map plugin to visualize the workout routes data on a map.

datasette install datasette-geojson-map
datasette healthkit.db

Decisions

  • Only the 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".
    • The descendent workoutEvent and workoutStatistics elements are represented as JSON columns.
    • The descendent 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.
    • The JSON columns can be verbose and result in large HTML table cell sizes, making it difficult to browse the results. In this case, it may be useful to specify the truncate_cells_html setting datasette healthkit.db --setting truncate_cells_html 40. Note that this setting does not appear to be compatible with the datasette-pretty-json plugin.
  • ActivitySummary elements are inserted as rows to a table named "ActivitySummary".
  • 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:
    • 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.

Dependencies

~42–57MB
~1M SLoC