Freebie • Step-by-Step

Personal Gym Analytics

Visualizing Apple Health XML exports and workout logs locally with Python.

The Problem: Trapped Data

I realized my health data was trapped in proprietary apps. I didn't want to spin up heavy enterprise tools like Prometheus or Kubernetes just to see if my sleep affected my gym performance. I needed something simple, local, and visual.

Step 1: Export Your Apple Health Data

Open the Health app on your iPhone, click your profile in the top right, and scroll down to Export All Health Data. Airdrop the resulting export.zip to your Mac and extract it. You will find an export.xml file.

Step 2: The Script

I wrote a simple Python script utilizing pandas and matplotlib to parse the XML, locate your Active Energy Burned and Sleep Analysis metrics, and plot them side by side.

import pandas as pd
import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET

# 1. Load the XML data
tree = ET.parse('apple_health_export/export.xml')
root = tree.getroot()

# 2. Extract records into a list
records = []
for record in root.findall('Record'):
    records.append({
        'type': record.get('type'),
        'value': record.get('value'),
        'date': record.get('creationDate')
    })

# 3. Create DataFrame and cleanup
df = pd.DataFrame(records)
df['date'] = pd.to_datetime(df['date'])

# ... add custom filtering here for HKQuantityTypeIdentifierActiveEnergyBurned
# Plot visually with Matplotlib
plt.figure(figsize=(12,6))
# Customize as needed!
plt.plot(df['date'], df['value'])
plt.title('My Energy Burned')
plt.show()

Step 3: Run it visually

Make sure you have pandas and matplotlib installed via pip. Run the script, and it will pop up a window charting your health. Tweak the type filter to target Sleep Analysis, Heart Rate, or Step Count. It's totally free, stays localized on your machine, and doesn't require maintaining a fleet of Docker containers.

Enjoy this simple automation! Connect with me on LinkedIn if you build any cool visual charts off of it.