Skip to main content

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 instance
  • await auth.authenticate() — Cognito SRP login + AWS IAM credential exchange
  • await auth.ensure_valid() — Re-authenticate if credentials expired
  • auth.credentialsCradlewiseCredentials with access_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 firmware
  • await client.get_cradle_state(cradle_id) — Raw state dict
  • await client.get_cradle_online_status(cradle_id) — Online status
  • await client.get_firmware_data(cradle_id) — Firmware version

Sleep Analytics:

  • await client.fetch_sleep_analytics(cradle) — Aggregated sleep data → SleepAnalytics
  • await client.get_sleep_events(baby_id) — Raw sleep events
  • await 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 (requires awsiotsdk)
  • await mqtt.connect(access_key, secret_key, session_token, cradle_ids, on_state_update) — Connect and subscribe
  • await mqtt.reconnect(...) — Reconnect with fresh credentials
  • await mqtt.disconnect() — Disconnect
  • mqtt.availablebool, connection status

Exceptions

  • CradlewiseError — Base exception
  • CradlewiseAuthError — 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 authentication
  • boto3 — AWS IAM credential exchange
  • aiohttp — Async HTTP client
  • awsiotsdk — AWS IoT MQTT (optional, for real-time updates)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycradlewise-0.3.1.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycradlewise-0.3.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pycradlewise-0.3.1.tar.gz.

File metadata

  • Download URL: pycradlewise-0.3.1.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycradlewise-0.3.1.tar.gz
Algorithm Hash digest
SHA256 44400f35e1c79707ee0984c5ab8292079b14ed45daa65e6d872e83e942977d20
MD5 7b918d54825ae9079871107a956bc053
BLAKE2b-256 eea5eac0e4a5e31183c59fea53cebd04190602867ab517ca9ac9f3546c131368

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycradlewise-0.3.1.tar.gz:

Publisher: publish.yml on jlamendo/pycradlewise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycradlewise-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pycradlewise-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycradlewise-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdb28e6ff51c93f953e56e5cdd5851896d28a7057f3d37747d6bf619a67a0a18
MD5 ef95ae4ad662daa80067c46a8429d311
BLAKE2b-256 79e23ba84ade0af8b6d7b8e3ea7504dfbbcb10d8e2fefbebd4c9ad086a51dfac

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycradlewise-0.3.1-py3-none-any.whl:

Publisher: publish.yml on jlamendo/pycradlewise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page