renpho-api 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {renpho_api-0.2.1 → renpho_api-0.3.0}/PKG-INFO +68 -3
- {renpho_api-0.2.1 → renpho_api-0.3.0}/README.md +67 -2
- {renpho_api-0.2.1 → renpho_api-0.3.0}/pyproject.toml +1 -1
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/cli.py +64 -26
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/client.py +275 -29
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/constants.py +12 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/export.py +3 -1
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/PKG-INFO +68 -3
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/SOURCES.txt +3 -1
- {renpho_api-0.2.1 → renpho_api-0.3.0}/tests/test_client.py +43 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/tests/test_crypto.py +14 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/tests/test_export.py +5 -0
- renpho_api-0.3.0/tests/test_friends.py +168 -0
- renpho_api-0.3.0/tests/test_hardening.py +147 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/__init__.py +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/crypto.py +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho/girth.py +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/dependency_links.txt +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/entry_points.txt +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/requires.txt +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/renpho_api.egg-info/top_level.txt +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/setup.cfg +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/tests/test_constants.py +0 -0
- {renpho_api-0.2.1 → renpho_api-0.3.0}/tests/test_girth.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: renpho-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Unofficial Python client for the Renpho Health API — pull body composition data from Renpho smart scales and body girth data from smart tape measures.
|
|
5
5
|
Author: danvaneijck
|
|
6
6
|
License-Expression: MIT
|
|
@@ -66,6 +66,9 @@ recent, and save everything to `renpho_data/` as JSON and CSV. If the account ha
|
|
|
66
66
|
a smart tape measure it also writes `girth.json` / `girth.csv`; accounts without
|
|
67
67
|
one simply report no girth records.
|
|
68
68
|
|
|
69
|
+
Family members linked to the account are saved to `family_members.json`, and
|
|
70
|
+
measurements are tagged with a `userName` field.
|
|
71
|
+
|
|
69
72
|
### Environment variables
|
|
70
73
|
|
|
71
74
|
| Variable | Required | Description |
|
|
@@ -74,6 +77,7 @@ one simply report no girth records.
|
|
|
74
77
|
| `RENPHO_PASSWORD` | Yes | Your Renpho account password |
|
|
75
78
|
| `RENPHO_DEBUG` | No | Set to `1` to print API request/response details |
|
|
76
79
|
| `RENPHO_OUTPUT_DIR` | No | Output directory (default: `renpho_data`) |
|
|
80
|
+
| `RENPHO_FRIEND_ID` | No | Read this friend's daily data instead of your own (see [Reading through a friend account](#reading-through-a-friend-account)) |
|
|
77
81
|
|
|
78
82
|
## Library Usage
|
|
79
83
|
|
|
@@ -123,6 +127,67 @@ save_json(measurements, "my_data.json")
|
|
|
123
127
|
save_csv(measurements, "my_data.csv")
|
|
124
128
|
```
|
|
125
129
|
|
|
130
|
+
### Family members (sub-users)
|
|
131
|
+
|
|
132
|
+
Profiles added under your account in the app (e.g. family members sharing a
|
|
133
|
+
scale) can be listed with `get_family_members()`. The logged-in user is not part
|
|
134
|
+
of that list; their own profile is in `client.user_info`.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
names = {str(client.user_id): client.user_info["accountName"]}
|
|
138
|
+
for member in client.get_family_members():
|
|
139
|
+
names[str(member["id"])] = member["accountName"]
|
|
140
|
+
|
|
141
|
+
# {'5981614576857776000': 'Alice', '5991064042346217344': 'Bob'}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Each entry is a full profile dict. Its `id` matches the `userIds` listed per
|
|
145
|
+
scale in `get_device_info()` and the `bUserId` field on measurement records.
|
|
146
|
+
Compare IDs as strings, since they arrive as both `int` and `str`.
|
|
147
|
+
|
|
148
|
+
### Reading through a friend account
|
|
149
|
+
|
|
150
|
+
Renpho allows one active session per account, so logging in with your main
|
|
151
|
+
account signs the phone app out. To sync without that, read your data through
|
|
152
|
+
Renpho's friends feature from a second account:
|
|
153
|
+
|
|
154
|
+
1. Create a second Renpho account with an email and password. An account
|
|
155
|
+
created with "Sign in with Google" or Apple has no password and can't log in
|
|
156
|
+
through the API.
|
|
157
|
+
2. In the Renpho app, add the second account as a friend of your main account
|
|
158
|
+
and accept the request.
|
|
159
|
+
3. Log in as the second account and read your main account's data:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
client = RenphoClient("second@example.com", "password")
|
|
163
|
+
friend = client.get_friends()[0] # {"userId", "accountName", ...}
|
|
164
|
+
|
|
165
|
+
days = client.get_friend_measurements(friend["userId"])
|
|
166
|
+
# [{"day": "2026-11-02", "timeStamp": ..., "weight": 79.5, "bodyfat": 20.1, ...}, ...]
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
With the CLI, set `RENPHO_FRIEND_ID` to the friend's `userId`. It writes
|
|
170
|
+
`friend_daily.json` and `friend_daily.csv` instead of the usual files.
|
|
171
|
+
|
|
172
|
+
`get_friend_trend(friend_id, param)` returns the daily points for a single
|
|
173
|
+
parameter, and `get_friend_summary()` and `get_friend_measure_days()` return
|
|
174
|
+
the server's raw responses.
|
|
175
|
+
|
|
176
|
+
Limits of the friend endpoints:
|
|
177
|
+
|
|
178
|
+
- One value per day (the last weigh-in that day).
|
|
179
|
+
- Body composition values only on days the scale measured them.
|
|
180
|
+
- One call covers a limited window. For older data, move `end_time` (unix
|
|
181
|
+
seconds) back.
|
|
182
|
+
- No segmental or girth data.
|
|
183
|
+
- Days are grouped by a whole-hour UTC offset, by default this machine's
|
|
184
|
+
(`time_zone=` to override).
|
|
185
|
+
|
|
186
|
+
This approach was worked out in
|
|
187
|
+
[#14](https://github.com/danvaneijck/renpho-api/issues/14), with a reference
|
|
188
|
+
implementation at
|
|
189
|
+
[DawidKrynski/renpho-friends](https://github.com/DawidKrynski/renpho-friends).
|
|
190
|
+
|
|
126
191
|
### Multiple Renpho accounts on one email
|
|
127
192
|
|
|
128
193
|
Some users end up with **two Renpho accounts under the same email** — for
|
|
@@ -204,8 +269,8 @@ Requests time out after 10 s to connect and 30 s to read by default. Pass
|
|
|
204
269
|
password, so they cannot log in through the API.
|
|
205
270
|
- **The phone app logs you out after a sync.** Renpho allows one active
|
|
206
271
|
session per account, so every `login()` ends the app's session. If you run
|
|
207
|
-
scheduled syncs,
|
|
208
|
-
|
|
272
|
+
scheduled syncs, read your data from a second account instead (see
|
|
273
|
+
[Reading through a friend account](#reading-through-a-friend-account)).
|
|
209
274
|
|
|
210
275
|
## Smart Tape Measure (body girth)
|
|
211
276
|
|
|
@@ -40,6 +40,9 @@ recent, and save everything to `renpho_data/` as JSON and CSV. If the account ha
|
|
|
40
40
|
a smart tape measure it also writes `girth.json` / `girth.csv`; accounts without
|
|
41
41
|
one simply report no girth records.
|
|
42
42
|
|
|
43
|
+
Family members linked to the account are saved to `family_members.json`, and
|
|
44
|
+
measurements are tagged with a `userName` field.
|
|
45
|
+
|
|
43
46
|
### Environment variables
|
|
44
47
|
|
|
45
48
|
| Variable | Required | Description |
|
|
@@ -48,6 +51,7 @@ one simply report no girth records.
|
|
|
48
51
|
| `RENPHO_PASSWORD` | Yes | Your Renpho account password |
|
|
49
52
|
| `RENPHO_DEBUG` | No | Set to `1` to print API request/response details |
|
|
50
53
|
| `RENPHO_OUTPUT_DIR` | No | Output directory (default: `renpho_data`) |
|
|
54
|
+
| `RENPHO_FRIEND_ID` | No | Read this friend's daily data instead of your own (see [Reading through a friend account](#reading-through-a-friend-account)) |
|
|
51
55
|
|
|
52
56
|
## Library Usage
|
|
53
57
|
|
|
@@ -97,6 +101,67 @@ save_json(measurements, "my_data.json")
|
|
|
97
101
|
save_csv(measurements, "my_data.csv")
|
|
98
102
|
```
|
|
99
103
|
|
|
104
|
+
### Family members (sub-users)
|
|
105
|
+
|
|
106
|
+
Profiles added under your account in the app (e.g. family members sharing a
|
|
107
|
+
scale) can be listed with `get_family_members()`. The logged-in user is not part
|
|
108
|
+
of that list; their own profile is in `client.user_info`.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
names = {str(client.user_id): client.user_info["accountName"]}
|
|
112
|
+
for member in client.get_family_members():
|
|
113
|
+
names[str(member["id"])] = member["accountName"]
|
|
114
|
+
|
|
115
|
+
# {'5981614576857776000': 'Alice', '5991064042346217344': 'Bob'}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Each entry is a full profile dict. Its `id` matches the `userIds` listed per
|
|
119
|
+
scale in `get_device_info()` and the `bUserId` field on measurement records.
|
|
120
|
+
Compare IDs as strings, since they arrive as both `int` and `str`.
|
|
121
|
+
|
|
122
|
+
### Reading through a friend account
|
|
123
|
+
|
|
124
|
+
Renpho allows one active session per account, so logging in with your main
|
|
125
|
+
account signs the phone app out. To sync without that, read your data through
|
|
126
|
+
Renpho's friends feature from a second account:
|
|
127
|
+
|
|
128
|
+
1. Create a second Renpho account with an email and password. An account
|
|
129
|
+
created with "Sign in with Google" or Apple has no password and can't log in
|
|
130
|
+
through the API.
|
|
131
|
+
2. In the Renpho app, add the second account as a friend of your main account
|
|
132
|
+
and accept the request.
|
|
133
|
+
3. Log in as the second account and read your main account's data:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
client = RenphoClient("second@example.com", "password")
|
|
137
|
+
friend = client.get_friends()[0] # {"userId", "accountName", ...}
|
|
138
|
+
|
|
139
|
+
days = client.get_friend_measurements(friend["userId"])
|
|
140
|
+
# [{"day": "2026-11-02", "timeStamp": ..., "weight": 79.5, "bodyfat": 20.1, ...}, ...]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
With the CLI, set `RENPHO_FRIEND_ID` to the friend's `userId`. It writes
|
|
144
|
+
`friend_daily.json` and `friend_daily.csv` instead of the usual files.
|
|
145
|
+
|
|
146
|
+
`get_friend_trend(friend_id, param)` returns the daily points for a single
|
|
147
|
+
parameter, and `get_friend_summary()` and `get_friend_measure_days()` return
|
|
148
|
+
the server's raw responses.
|
|
149
|
+
|
|
150
|
+
Limits of the friend endpoints:
|
|
151
|
+
|
|
152
|
+
- One value per day (the last weigh-in that day).
|
|
153
|
+
- Body composition values only on days the scale measured them.
|
|
154
|
+
- One call covers a limited window. For older data, move `end_time` (unix
|
|
155
|
+
seconds) back.
|
|
156
|
+
- No segmental or girth data.
|
|
157
|
+
- Days are grouped by a whole-hour UTC offset, by default this machine's
|
|
158
|
+
(`time_zone=` to override).
|
|
159
|
+
|
|
160
|
+
This approach was worked out in
|
|
161
|
+
[#14](https://github.com/danvaneijck/renpho-api/issues/14), with a reference
|
|
162
|
+
implementation at
|
|
163
|
+
[DawidKrynski/renpho-friends](https://github.com/DawidKrynski/renpho-friends).
|
|
164
|
+
|
|
100
165
|
### Multiple Renpho accounts on one email
|
|
101
166
|
|
|
102
167
|
Some users end up with **two Renpho accounts under the same email** — for
|
|
@@ -178,8 +243,8 @@ Requests time out after 10 s to connect and 30 s to read by default. Pass
|
|
|
178
243
|
password, so they cannot log in through the API.
|
|
179
244
|
- **The phone app logs you out after a sync.** Renpho allows one active
|
|
180
245
|
session per account, so every `login()` ends the app's session. If you run
|
|
181
|
-
scheduled syncs,
|
|
182
|
-
|
|
246
|
+
scheduled syncs, read your data from a second account instead (see
|
|
247
|
+
[Reading through a friend account](#reading-through-a-friend-account)).
|
|
183
248
|
|
|
184
249
|
## Smart Tape Measure (body girth)
|
|
185
250
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "renpho-api"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Unofficial Python client for the Renpho Health API — pull body composition data from Renpho smart scales and body girth data from smart tape measures."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -23,6 +23,7 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
23
23
|
password = os.getenv("RENPHO_PASSWORD", "")
|
|
24
24
|
debug = os.getenv("RENPHO_DEBUG", "").lower() in ("1", "true", "yes")
|
|
25
25
|
output_dir = Path(os.getenv("RENPHO_OUTPUT_DIR", "renpho_data"))
|
|
26
|
+
friend_id = os.getenv("RENPHO_FRIEND_ID", "").strip()
|
|
26
27
|
|
|
27
28
|
if not email or not password:
|
|
28
29
|
print("Missing credentials!\n")
|
|
@@ -39,6 +40,10 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
39
40
|
client.login()
|
|
40
41
|
print(f"Logged in! User ID: {client.user_id}")
|
|
41
42
|
|
|
43
|
+
if friend_id:
|
|
44
|
+
_fetch_friend(client, friend_id, output_dir)
|
|
45
|
+
return
|
|
46
|
+
|
|
42
47
|
# Step 2: Device info
|
|
43
48
|
print("Getting device info...")
|
|
44
49
|
device_info = client.get_device_info()
|
|
@@ -55,38 +60,43 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
55
60
|
print(f" Device info keys: {list(device_info.keys())}")
|
|
56
61
|
sys.exit(1)
|
|
57
62
|
|
|
63
|
+
# Names are cosmetic — a failed family lookup must not abort the run.
|
|
64
|
+
try:
|
|
65
|
+
family = client.get_family_members()
|
|
66
|
+
except (RenphoAPIError, requests.RequestException) as e:
|
|
67
|
+
print(f" Family member lookup failed: {e}")
|
|
68
|
+
family = []
|
|
69
|
+
if family:
|
|
70
|
+
save_json(family, output_dir / "family_members.json")
|
|
71
|
+
user_names = {
|
|
72
|
+
str(m["id"]): m["accountName"]
|
|
73
|
+
for m in family
|
|
74
|
+
if m.get("id") is not None and m.get("accountName")
|
|
75
|
+
}
|
|
76
|
+
if client.user_info and client.user_info.get("accountName"):
|
|
77
|
+
user_names[str(client.user_id)] = client.user_info["accountName"]
|
|
78
|
+
|
|
58
79
|
print(f"\nFound {len(scales)} scale table(s):")
|
|
59
80
|
for i, scale in enumerate(scales):
|
|
60
81
|
table = scale.get("tableName", "unknown")
|
|
61
82
|
count = scale.get("count", 0)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Step 3: Fetch measurements
|
|
66
|
-
all_measurements: list[dict] = []
|
|
67
|
-
for scale in scales:
|
|
68
|
-
table_name = scale.get("tableName")
|
|
69
|
-
count = scale.get("count", 0)
|
|
70
|
-
user_ids = scale.get("userIds", [])
|
|
71
|
-
|
|
72
|
-
if not table_name or count == 0:
|
|
73
|
-
continue
|
|
74
|
-
|
|
75
|
-
uid = client.user_id
|
|
76
|
-
if user_ids and uid not in user_ids:
|
|
77
|
-
uid = user_ids[0]
|
|
78
|
-
|
|
79
|
-
print(f"Fetching measurements (table: {table_name}, total: {count})...")
|
|
80
|
-
measurements = client.get_measurements(table_name, uid, count)
|
|
81
|
-
all_measurements.extend(measurements)
|
|
82
|
-
|
|
83
|
-
if all_measurements:
|
|
84
|
-
# Sort newest first
|
|
85
|
-
all_measurements.sort(
|
|
86
|
-
key=lambda m: m.get("timeStamp", 0) or 0,
|
|
87
|
-
reverse=True,
|
|
83
|
+
users = ", ".join(
|
|
84
|
+
f"{user_names[str(u)]} ({u})" if str(u) in user_names else str(u)
|
|
85
|
+
for u in scale.get("userIds", [])
|
|
88
86
|
)
|
|
87
|
+
print(f" [{i}] table={table}, records={count}, users=[{users}]")
|
|
88
|
+
|
|
89
|
+
# Step 3: Fetch measurements. get_all_measurements() tries the body
|
|
90
|
+
# composition endpoint before the legacy one, so it also reads tables whose
|
|
91
|
+
# count device/count reports as 0 (common for impedance scales).
|
|
92
|
+
print("\nFetching measurements...")
|
|
93
|
+
all_measurements = client.get_all_measurements(device_info=device_info)
|
|
94
|
+
for m in all_measurements:
|
|
95
|
+
name = user_names.get(str(m.get("bUserId", client.user_id)))
|
|
96
|
+
if name:
|
|
97
|
+
m["userName"] = name
|
|
89
98
|
|
|
99
|
+
if all_measurements:
|
|
90
100
|
print(f"\nTotal: {len(all_measurements)} measurement(s)")
|
|
91
101
|
|
|
92
102
|
# Display most recent 5
|
|
@@ -134,3 +144,31 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
134
144
|
save_json(client.user_info, output_dir / "user_profile.json")
|
|
135
145
|
|
|
136
146
|
print(f"\nDone! Data saved to '{output_dir}/' folder.")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _fetch_friend(client: RenphoClient, friend_id: str, output_dir: Path) -> None:
|
|
150
|
+
"""Friend mode: read another account's daily data via the friends feature."""
|
|
151
|
+
print(f"Fetching daily data for friend {friend_id}...")
|
|
152
|
+
records = client.get_friend_measurements(friend_id)
|
|
153
|
+
if not records:
|
|
154
|
+
print(" No data returned. Check that RENPHO_FRIEND_ID is a userId from")
|
|
155
|
+
print(" the friends list and that the friend request was accepted.")
|
|
156
|
+
friends = client.get_friends()
|
|
157
|
+
if friends:
|
|
158
|
+
print(" Friends of this account:")
|
|
159
|
+
for f in friends:
|
|
160
|
+
print(f" {f.get('userId')} {f.get('accountName', '')}")
|
|
161
|
+
return
|
|
162
|
+
|
|
163
|
+
print(f"Total: {len(records)} day(s), newest {records[0]['day']}")
|
|
164
|
+
for i, r in enumerate(records[:5]):
|
|
165
|
+
print(f"\n{'=' * 55}")
|
|
166
|
+
print(f" Day {r['day']}")
|
|
167
|
+
print(f"{'=' * 55}")
|
|
168
|
+
print(format_measurement(r))
|
|
169
|
+
if len(records) > 5:
|
|
170
|
+
print(f"\n ... and {len(records) - 5} more")
|
|
171
|
+
|
|
172
|
+
save_json(records, output_dir / "friend_daily.json")
|
|
173
|
+
save_csv(records, output_dir / "friend_daily.csv")
|
|
174
|
+
print(f"\nDone! Data saved to '{output_dir}/' folder.")
|