Python client for the Withings API
Project description
python-withings
Withings API Client for Python.
Official API reference: https://developer.withings.com/api-reference
Installation
uv add legnoh-withings
Quick Start
1. Build an authorization URL
from withings import WithingsClient
client = WithingsClient(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
redirect_uri="https://example.com/callback",
)
auth_url = client.build_authorization_url(
scopes=["user.info", "user.metrics", "user.activity", "user.sleep.events"],
state="random-csrf-state",
)
print(auth_url)
2. Exchange authorization code for tokens
token = client.request_access_token(code="AUTHORIZATION_CODE")
print(token.access_token)
3. Call APIs
from datetime import date, datetime, timezone
# User-linked devices
devices = client.get_user_devices()
# Body measures
measures = client.get_measures(lastupdate=1710000000)
# Daily activity
activity = client.get_activity(
startdateymd=date(2026, 3, 1),
enddateymd=date(2026, 3, 7),
data_fields=["steps", "distance", "calories"],
)
# Sleep summary
sleep_summary = client.get_sleep_summary(
startdateymd=date(2026, 3, 1),
enddateymd=date(2026, 3, 7),
)
# High-frequency sleep data
sleep_detail = client.get_sleep(
startdate=datetime(2026, 3, 1, 0, 0, tzinfo=timezone.utc),
enddate=datetime(2026, 3, 2, 0, 0, tzinfo=timezone.utc),
)
startdateymd and enddateymd accept datetime.date.
startdate and enddate accept datetime.datetime and are internally converted to Unix timestamps.
Implemented Features
- OAuth2 authorization URL builder
- OAuth2 token exchange (
authorization_code) - OAuth2 token refresh (
refresh_token) - Generic API call entrypoint (
call) - User API (
getdevice,getgoals,link,unlink) - Measure API (
getmeas,getactivity,getintradayactivity,getworkouts) - Sleep API (
get,getsummary) - Heart API (
list,get) - Notify API (
subscribe,list,get,update,revoke)
Error Handling
When Withings response status is not 0, the client raises WithingsApiError.
from withings import WithingsApiError
try:
client.get_user_devices()
except WithingsApiError as e:
print(e.status)
print(e)
Notes
- HTTP requests to Withings are sent as
application/x-www-form-urlencoded. - If the token is near expiry, the client refreshes it with
refresh_tokenbefore API calls.
Development
Setup
uv sync
Run tests
uv run pytest
Run example scripts
uv run python your_script.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file legnoh_withings-0.0.1.tar.gz.
File metadata
- Download URL: legnoh_withings-0.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93191d836041ec352ccebf5f9f5eb0dc449b673bf2d1122386a88fb27a35d0e7
|
|
| MD5 |
a5299c41f96af2d163197a93a552e823
|
|
| BLAKE2b-256 |
2823c034bdb82ce280e9f5c5bca1278dd99bfc94e4232ed9b0f81aa98b0b68fa
|
File details
Details for the file legnoh_withings-0.0.1-py3-none-any.whl.
File metadata
- Download URL: legnoh_withings-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e6cdb99b222d7e1a1997bf8f4528ef781cb719a56b5c2557a3db273b19ef29
|
|
| MD5 |
7574a366196364ee4370bc562c0c4b3e
|
|
| BLAKE2b-256 |
e2aa60ebac541561ae3f56663c5d3406aecd1d5623f9ffde3db5db8163bcf7e0
|