Stu Mason
Stu Mason

Self-Hosting My Polar Health Data

Stu Mason3 min read

Polar's API only keeps 28 days of data. Built a server to sync and store it all permanently so I can actually analyze trends.

Self-Hosting My Polar Health Data

Polar's API has a problem: it only gives you access to the last 28-30 days of data. After that, it's gone. Not deleted from Polar - they still have it - but you can't access it through the API.

If you've been tracking sleep for six months and want to analyze trends, you're out of luck. Unless you've been syncing it yourself.

So I built polar-flow-server.

What It Does

It's a self-hosted server that syncs all your Polar data automatically and stores it in PostgreSQL. Sleep, HRV, exercises, daily activity, heart rate - all nine endpoints, synced every hour.

Once synced, the data is yours. Forever. Query it however you want.

The Stack

Built it with Litestar (async Python web framework), SQLAlchemy 2.0 for the database layer, and PostgreSQL for storage. HTMX and Tailwind for the admin dashboard because I didn't want to write a React frontend for something I'd use alone.

Uses my polar-flow SDK under the hood for all the Polar API calls.

Running It

Docker compose and you're done:

curl -O https://raw.githubusercontent.com/StuMason/polar-flow-server/main/docker-compose.prod.yml
docker-compose -f docker-compose.prod.yml up -d

Visit localhost:8000/admin, connect your Polar credentials, hit sync. Your data starts flowing in.

After initial sync, it checks for new data every hour automatically. You don't need to touch it.

The Dashboard

Built an HTMX-powered admin dashboard that shows:

  • Recent sleep data and scores
  • HRV trends
  • Exercise history
  • Daily activity summaries
  • Sync status and history

Nothing fancy, but it's nice to have a quick view of your data without writing SQL queries.

Multi-User Support

Designed it to handle multiple users from the start. Each user gets their own API key, their own OAuth connection to Polar, their own synced data. Rate limiting per user to stay within Polar's API limits.

If you want to run this for a few people (family, team, whatever), it's set up for that.

The API

The server exposes a REST API on top of your synced data:

curl -H "X-API-Key: your-key" \
  http://localhost:8000/api/v1/sleep?days=90

Query by date range, aggregate however you want. Build whatever visualizations or analysis tools you need on top of it.

Why Self-Host

I could've just built a script that syncs to a CSV file. But I wanted:

  1. Automatic background syncing - I don't want to remember to run a script
  2. Proper storage - PostgreSQL means I can query efficiently
  3. API access - Build other tools on top of the data
  4. Historical analysis - Six months of data instead of 28 days

It's running on my Coolify server now. Syncs silently in the background. I've got months of sleep data I can actually analyze instead of watching it disappear after a month.

The repo: github.com/StuMason/polar-flow-server

Get the Friday email

What I shipped this week, what I learned, one useful thing.

No spam. Unsubscribe anytime. Privacy policy.