Ouraring Python API Docs | dltHub

Build a Ouraring-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

Oura is a health-data API providing programmatic access to Oura Ring data including sleep, activity, readiness, heart rate, sessions, tags, and device configuration. The REST API base URL is https://api.ouraring.com/v2 and All requests require an OAuth2 access token (Bearer) in the Authorization header.

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Ouraring data in under 10 minutes.


What data can I load from Ouraring?

Here are some of the endpoints you can load from Ouraring:

ResourceEndpointMethodData selectorDescription
daily_sleep/v2/usercollection/daily_sleepGETdataDaily readiness-like daily sleep summaries (multiple documents)
sleep/v2/usercollection/sleepGETdataNightly sleep records (detailed sleep documents)
daily_activity/v2/usercollection/daily_activityGETdataDaily activity summaries
personal_info/v2/usercollection/personal_infoGET(single object)User personal info (single document)
sessions/v2/usercollection/sessionGETdataGuided/unguided session records (time-series per session)
heart_rate/v2/usercollection/heart_rateGETdataHeart rate time-series documents (requires heartrate scope)
sleep_time/v2/usercollection/sleep_timeGETdataSleep timing recommendations and summaries
ring_configuration/v2/usercollection/ring_configurationGETdataDevice configuration documents
rest_mode_period/v2/usercollection/rest_mode_periodGETdataRest mode (do-not-disturb) periods
sandbox_sleep/v2/sandbox/usercollection/sleepGETdataSandbox endpoint returning fake sleep data for testing

How do I authenticate with the Ouraring API?

The Oura Cloud API uses OAuth2 (authorization code or client-side flows). Include the access token in requests as: Authorization: Bearer <access_token>. Token endpoint: https://api.ouraring.com/oauth/token. Scopes include email, personal, daily, heartrate, workout, tag, session, spo2.

1. Get your credentials

  1. Sign in to https://cloud.ouraring.com and register an OAuth application at https://cloud.ouraring.com/oauth/applications. 2) Note your Client ID and Client Secret. 3) Implement the OAuth2 authorization code flow (direct user to https://cloud.ouraring.com/oauth/authorize with client_id, redirect_uri, response_type=code and requested scopes). 4) Exchange the authorization code at https://api.ouraring.com/oauth/token for access_token and refresh_token. 5) Use the access_token in Authorization header; refresh using the token endpoint when expired.

2. Add them to .dlt/secrets.toml

[sources.ouraring_data_source] client_id = "YOUR_CLIENT_ID" client_secret = "YOUR_CLIENT_SECRET" access_token = "USER_ACCESS_TOKEN"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Ouraring API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python ouraring_data_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline ouraring_data_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset ouraring_data_data The duckdb destination used duckdb:/ouraring_data.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline ouraring_data_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads sleep and daily_sleep from the Ouraring API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def ouraring_data_source(access_token=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.ouraring.com/v2", "auth": { "type": "bearer", "access_token": access_token, }, }, "resources": [ {"name": "sleep", "endpoint": {"path": "usercollection/sleep", "data_selector": "data"}}, {"name": "daily_sleep", "endpoint": {"path": "usercollection/daily_sleep", "data_selector": "data"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="ouraring_data_pipeline", destination="duckdb", dataset_name="ouraring_data_data", ) load_info = pipeline.run(ouraring_data_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("ouraring_data_pipeline").dataset() sessions_df = data.sleep.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM ouraring_data_data.sleep LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("ouraring_data_pipeline").dataset() data.sleep.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Ouraring data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

  • 401 Unauthorized: access token missing, malformed, expired, or user revoked access. Fix: ensure Authorization: Bearer <access_token>, refresh tokens via https://api.ouraring.com/oauth/token when expired.

Missing scopes or subscription issues

  • 403 Forbidden: the token lacks the required scope for the endpoint or the user's Oura subscription has expired. Request only needed scopes during authorization and confirm user subscription.

Rate limiting

  • 429 Request Rate Limit Exceeded: V2 rate limit is documented as 5000 requests per 5 minutes. Use webhooks for real-time updates, batch requests, caching, and exponential backoff on 429 responses.

Pagination and result keys

  • Multi-document GET endpoints return JSON objects with a top-level "data" array containing records and a "next_token" (or next_token-like cursor) for pagination. Single-document endpoints return the document object directly (no "data" wrapper).

Webhook notes

  • Webhooks are recommended to avoid polling; when verifying webhook subscriptions Oura performs a verification GET and expects the challenge response. Validate x-oura-signature using your client secret for authenticity.

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Ouraring?

Request dlt skills, commands, AGENT.md files, and AI-native context.