Async Python client for the Cradlewise Smart Crib API
Project description
pycradlewise
Async Python client for the Cradlewise Smart Crib API.
Supports REST API polling and real-time AWS IoT MQTT push updates for cradle state, sleep analytics, and device monitoring.
Installation
pip install pycradlewise
Quick Start
import asyncio
from pycradlewise import CradlewiseAuth, CradlewiseClient, get_app_config
async def main():
# Load API config (auto-downloaded from Cradlewise app, cached to disk)
app_config = await get_app_config()
# Authenticate
auth = CradlewiseAuth(
email="you@example.com",
password="yourpassword",
app_config=app_config,
)
await auth.authenticate()
client = CradlewiseClient(auth)
# Discover cribs linked to your account
cradles = await client.discover_cradles()
for cradle_id, cradle in cradles.items():
print(f"{cradle.baby_name}: {cradle_id}")
# Fetch latest state
await client.update_cradle(cradle)
print(f" Online: {cradle.online}")
print(f" Sleep phase: {cradle.sleep_phase_name}")
print(f" Bouncing: {cradle.bouncing}")
print(f" Music: {cradle.music_playing}")
print(f" Light: {cradle.light_on}")
print(f" Temperature: {cradle.temperature}")
print(f" Humidity: {cradle.humidity}")
# Fetch sleep analytics
if cradle.baby_id:
analytics = await client.fetch_sleep_analytics(cradle)
print(f" Total sleep: {analytics.total_sleep_minutes} min")
print(f" Soothes: {analytics.total_soothe_count}")
asyncio.run(main())
Real-Time Updates (MQTT)
from pycradlewise import CradlewiseMqtt
mqtt = CradlewiseMqtt()
def on_update(cradle_id: str, state: dict):
print(f"Update from {cradle_id}: {state}")
await mqtt.connect(
access_key=auth.credentials.access_key,
secret_key=auth.credentials.secret_key,
session_token=auth.credentials.session_token,
cradle_ids=list(cradles.keys()),
on_state_update=on_update,
)
# mqtt.available == True when connected
# Call mqtt.disconnect() to clean up
API Reference
Bootstrap
get_app_config(cache_dir=None)— Download and cache Cradlewise app config (Cognito pool IDs, API endpoint). Only downloads once; subsequent calls read from cache.AppConfig— Dataclass:cognito_user_pool_id,cognito_app_client_id,cognito_app_client_secret,cognito_identity_pool_id,cognito_region,api_base_url
Authentication
CradlewiseAuth(email, password, app_config)— Create auth instanceawait auth.authenticate()— Cognito SRP login + AWS IAM credential exchangeawait auth.ensure_valid()— Re-authenticate if credentials expiredauth.credentials—CradlewiseCredentialswithaccess_key,secret_key,session_token
Client
CradlewiseClient(auth)— Create API client
Discovery:
await client.get_baby_profiles()— Baby profiles for the account →list[dict]await client.get_cradles_for_baby(baby_id)— Cradles paired with a baby →list[dict]await client.discover_cradles()— All cradles with baby associations →dict[str, CradlewiseCradle]
Cradle State:
await client.update_cradle(cradle)— Fetch and apply latest state, online status, and firmwareawait client.get_cradle_state(cradle_id)— Raw state dictawait client.get_cradle_online_status(cradle_id)— Online statusawait client.get_firmware_data(cradle_id)— Firmware version
Sleep Analytics:
await client.fetch_sleep_analytics(cradle)— Aggregated sleep data →SleepAnalyticsawait client.get_sleep_events(baby_id)— Raw sleep eventsawait client.get_analytics(baby_id)— Raw analytics data
Models
CradlewiseCradle — Represents a smart crib with computed properties from state:
| Property | Type | Description |
|---|---|---|
cradle_id |
str |
Unique cradle identifier |
baby_id |
str? |
Associated baby ID |
baby_name |
str? |
Baby's name |
online |
bool |
Connection status |
firmware_version |
str? |
Current firmware |
baby_present |
bool? |
Baby detected in crib |
sleep_phase_name |
str? |
Human-readable sleep phase (away/awake/stirring/sleep) |
baby_needs_attention |
bool? |
Attention alert |
bouncing |
bool? |
Rocking motor active |
bounce_amplitude |
int? |
Rocking intensity |
music_playing |
bool? |
Music/white noise active |
music_volume |
int? |
Music volume level |
light_on |
bool? |
Nightlight active |
light_intensity |
int? |
Light brightness |
temperature |
float? |
Room temperature |
humidity |
float? |
Room humidity |
noise_level |
float? |
Ambient noise level |
battery_life |
int? |
Battery percentage |
charging |
bool? |
Charging status |
cradle_mode |
str? |
Operating mode |
update_state(dict) |
method | Merge partial MQTT delta |
SleepAnalytics — Aggregated sleep data:
| Field | Type | Description |
|---|---|---|
total_sleep_minutes |
int |
Total sleep time |
total_awake_minutes |
int |
Total awake time |
total_soothe_count |
int |
Number of soothing interventions |
nap_count |
int |
Number of naps |
longest_nap_minutes |
int |
Longest nap duration |
events |
list[dict] |
Raw sleep event list |
MQTT
CradlewiseMqtt()— Create MQTT client (requiresawsiotsdk)await mqtt.connect(access_key, secret_key, session_token, cradle_ids, on_state_update)— Connect and subscribeawait mqtt.reconnect(...)— Reconnect with fresh credentialsawait mqtt.disconnect()— Disconnectmqtt.available—bool, connection status
Exceptions
CradlewiseError— Base exceptionCradlewiseAuthError— Authentication failures (bad credentials, expired tokens)CradlewiseApiError— API request failures (HTTP errors, malformed responses)
Architecture
Phone App → Cradlewise APK → amplifyconfiguration.json
↓
get_app_config()
↓
Cognito User Pool IDs
↓
CradlewiseAuth (Cognito SRP + IAM)
↓
┌───────────────┴───────────────┐
↓ ↓
CradlewiseClient CradlewiseMqtt
(REST, SigV4-signed) (AWS IoT WebSocket)
↓ ↓
Cradle state, analytics Real-time state deltas
The library auto-downloads and caches the Cradlewise Android app's Amplify config on first use, extracting the Cognito pool IDs needed for authentication. All REST API requests are signed with AWS SigV4 using temporary IAM credentials obtained through the Cognito identity pool.
Dependencies
pycognito— Cognito SRP authenticationboto3— AWS IAM credential exchangeaiohttp— Async HTTP clientawsiotsdk— AWS IoT MQTT (optional, for real-time updates)
License
MIT
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 pycradlewise-0.2.0.tar.gz.
File metadata
- Download URL: pycradlewise-0.2.0.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0dfb09a7c5cb3addd24c847e3f3800205275fd1c4c4325e200a861fabc96100
|
|
| MD5 |
537bf7838a3a5e05039dfa7c52b8f397
|
|
| BLAKE2b-256 |
b00c5b1c54ee2262b3022e5c0214f9fadae452b4e02a3f1e761141dde9407d0c
|
Provenance
The following attestation bundles were made for pycradlewise-0.2.0.tar.gz:
Publisher:
publish.yml on jlamendo/pycradlewise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycradlewise-0.2.0.tar.gz -
Subject digest:
b0dfb09a7c5cb3addd24c847e3f3800205275fd1c4c4325e200a861fabc96100 - Sigstore transparency entry: 1205431254
- Sigstore integration time:
-
Permalink:
jlamendo/pycradlewise@90ca8693e4335e159b1d3be6d19017965e4a0315 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jlamendo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@90ca8693e4335e159b1d3be6d19017965e4a0315 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pycradlewise-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pycradlewise-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81890b3081c7d4930d165d38ed831245abf20af896520bdadcb0be2b96880836
|
|
| MD5 |
671d910d91decb024fddddd7be0c9c19
|
|
| BLAKE2b-256 |
706740ccde2918a81ae0eb85e89fc773e74632c9f1d5441f511f9fb6834f53cd
|
Provenance
The following attestation bundles were made for pycradlewise-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on jlamendo/pycradlewise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycradlewise-0.2.0-py3-none-any.whl -
Subject digest:
81890b3081c7d4930d165d38ed831245abf20af896520bdadcb0be2b96880836 - Sigstore transparency entry: 1205431274
- Sigstore integration time:
-
Permalink:
jlamendo/pycradlewise@90ca8693e4335e159b1d3be6d19017965e4a0315 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jlamendo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@90ca8693e4335e159b1d3be6d19017965e4a0315 -
Trigger Event:
release
-
Statement type: