Skip to main content

blueair_api

GitHub Release GitHub Activity License

Project Maintenance BuyMeCoffee

Api Wrapper for BlueAir API using async in python. This was inspired by this guide to be a lightweight wrapper with simple error handling.

a lot of this is based on hass-blueair.

Features

  • REST API — async device discovery, sensor polling, and control commands for both legacy and AWS-based Blueair devices.
  • MQTT real-time updates — receive sensor data and device state changes via AWS IoT WebSocket with sub-second latency instead of 5-minute polling.
  • Automatic reconnect with credential refresh — MQTT tokens expire after 24 hours; the client refreshes credentials and reconnects with exponential backoff on unexpected disconnects.
  • Split AWS regions when needed — keep the normal single region setting for most accounts, or configure separate Gigya account and BlueCloud device-control regions for accounts whose devices are hosted elsewhere. See AWS account and BlueCloud regions.
  • Data-driven SKU mapping — resolves device SKUs to human-readable product names via a built-in lookup table.
  • Per-device hardware detection — mood_brightness_max and fan_speed_count adapt automatically based on the device's hardware identifier.

Sessions, Authentication and Errors

  • Shared aiohttp sessions — pass client_session to reuse an existing session, such as Home Assistant's. cleanup_client_session() only closes a session the client created itself; a session you pass in is left open for its owner to close.
  • Re-authentication — concurrent requests share one login. The BlueCloud access token is refreshed shortly before the exp claim in the token, and a request rejected with an expired session re-authenticates and retries once.
  • Errors — every error is a BaseError, which is an aiohttp ClientError:
    • LoginError / SessionError (both AuthError): rejected credentials or session.
    • RateError: HTTP 429 rate limit.
    • ServerError: HTTP 5xx; does not discard the session.
    • ResponseError: any other unexpected status; also a ValueError.
    • RequestTimeoutError: a request took longer than 20 seconds; also a TimeoutError.
  • Debug logging — request and response logs mask credentials, tokens, session secrets, signatures and email addresses.

Development

Clone this repository and install the development environment:

git clone https://github.com/dahlb/blueair_api.git
cd blueair_api
scripts/setup

Use the repository scripts so commands run through the local .venv.

scripts/setup
scripts/test
scripts/lint

The underlying commands are:

./.venv/bin/pytest
./.venv/bin/prek run --all-files
./.venv/bin/mypy

mypy runs in strict mode (strict = true in pyproject.toml) over src/blueair_api. The Lint workflow runs the same check on every push and pull request.

Add or update pytest coverage for behavior changes. Fixture data for device info responses lives under tests/device_info.

Live Smoke Test

The live smoke test connects to a real Blueair account, loads and refreshes AWS devices, prints their state, starts the MQTT real-time listener, sends one sample control update to the first AWS device, and checks the legacy API.

scripts/live_smoke_test

Use it only when you want to exercise the live Blueair APIs. The sample control update writes the first AWS device's current LED brightness back to it, so the setting is unchanged but the control path and MQTT shadow update are exercised. The script then waits 5 minutes so MQTT messages can be observed.

To run non-interactively, put credentials in a local env file and pass it with --credentials-file. Supported keys are BLUEAIR_USERNAME/BLUEAIR_PASSWORD (see scripts/blueair_api.env.example); TOML and JSON files with username/password keys also work, as do BLUEAIR_USERNAME/BLUEAIR_PASSWORD environment variables.

scripts/live_smoke_test --credentials-file scripts/blueair_api.env --output-file /private/tmp/blueair_api.txt --read-only

Other options:

  • --output-file writes a full transcript (stdout, stderr, and logs) for later API debugging or fixture updates.
  • --read-only skips the sample control update while still loading devices and listening for MQTT messages.
  • --region selects the Blueair region (au, cn, eu, us; default us). --gigya-region and --cloud-region override the account-auth and device-control regions separately; see AWS account and BlueCloud regions.
  • --skip-legacy skips the legacy (non-AWS) API check.

Metadata

Release files for blueair-api 1.56.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blueair-api 1.56.9
File Size Uploaded Provenance Actions
blueair_api-1.56.9.tar.gz 92.4 kB Without provenance Details for blueair_api-1.56.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for blueair-api 1.56.9
File Interpreter ABI Platform Actions
blueair_api-1.56.9-py3-none-any.whl Python 3 none any Details for blueair_api-1.56.9-py3-none-any.whl

Total release size: 150.5 kB

Release files / blueair_api-1.56.9.tar.gz

Download URL blueair_api-1.56.9.tar.gz
Size 92.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ca4c734c5adb6fc26b8af7fddd89db12fe61a8b815a3e61637a563ebcfd7150b
BLAKE2b-256 checksum
How to use checksums
1c150cc10b94a000966a2764443be1d8542a823c7dca7fa591cf4c854eff3066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / blueair_api-1.56.9-py3-none-any.whl

Download URL blueair_api-1.56.9-py3-none-any.whl
Size 58.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
55910c19aecbc8b313250d8bca41f931f6004513cbf0abbf7c5771d76ec50b74
BLAKE2b-256 checksum
How to use checksums
fa9e30cca1a382c7f431be772b4e59bfdf443bfe40f4d525f9152104fbbe6382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for blueair-api 1.56.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.56.9 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page