Skip to main content

Async Python client for the Aranet Cloud REST API

Project description

aranet-cloud

python license version

Async Python client for the Aranet Cloud REST API.

Wraps every endpoint in the public Aranet Cloud OpenAPI 3.0 spec — 27 read-only GET endpoints — and returns typed dataclass models. Designed primarily as the backing library for the aranet-cloud-homeassistant HACS integration, but usable as a standalone Python client.

Status: Pre-release (0.1.x). The OpenAPI mapping is stable; the public Python surface may evolve as the HA integration drives requirements. Pin to a minor version in production.

Install

pip install aranet-cloud

Python 3.11+ required. Single runtime dependency: aiohttp.

Quick start

import asyncio
from aranet_cloud import AranetCloudClient

async def main() -> None:
    async with AranetCloudClient(api_key="...") as client:
        # List every sensor on your account
        sensors = await client.get_sensors()
        for s in sensors:
            print(f"  {s.serial}  {s.name:<30s}  type={s.type}")

        # Latest reading per (sensor × metric), with name resolution
        readings, links = await client.get_measurements_last()
        for r in readings:
            metric = links.name("metric", r.metric) or r.metric
            unit   = links.name("unit",   r.unit)   or r.unit
            print(f"  {r.sensor:>10s}  {metric:>22s}: {r.value} {unit}")

asyncio.run(main())

Output against a typical home/garden account:

  02D0C  Primary Bedroom               type=S4V1
  02E2C  Kitchen                       type=S4V1
  ...

  4205836           Temperature: 72.5 °F
  4205836              Humidity: 30 %
  4205836                    CO₂: 757 ppm
  4205836   Atmospheric Pressure: 697.9 mmHg
  ...

Authentication

The Aranet Cloud API uses a single header — ApiKey: <your-key>. No OAuth, no token refresh. Generate a key from your Aranet Cloud dashboard under Account → API.

AranetCloudClient(api_key="vku...")

What's covered

All 27 GET endpoints in the public OpenAPI spec:

Domain Methods
Sensors get_sensors, get_sensor, get_sensor_types, get_sensor_type
Measurements get_measurements_last, iter_measurements_history (paginated)
Telemetry get_telemetry_last, iter_telemetry_history (paginated)
Bases get_bases, get_base
Alarms get_alarms_actual, get_alarms_history, get_alarm_rules, get_alarm_rule
Assets get_assets, get_asset
Tags get_tags, get_tag
Catalog get_metrics, get_metric, get_unit
Attachments download_sensor_attachment, download_asset_attachment

See docs/architecture.md for the full API reference, edge cases discovered during live probing, and design notes.

Pagination

History endpoints are paginated by the server. The library hides the mechanics via async iterators:

async for reading in client.iter_measurements_history(sensor="4205836", hours=24):
    print(reading.time, reading.value)

The iterator follows the next token transparently until the server returns no more data. Mind the time windows/measurements/history without a sensor filter caps at 7 days; with a sensor filter it caps at 6 months.

Exception hierarchy

AranetError                       ← base; catch this for a blanket handler
├── AranetConnectionError         ← network, timeout, TLS, DNS
├── AranetAuthError               ← 401 (key wrong/missing/revoked) - NOT transient
├── AranetValidationError         ← 400 (carries correlation_id from API)
├── AranetRateLimitError          ← 429 (with retry_after if present)
├── AranetServerError             ← 5xx after exhausted retries
└── AranetNotFoundError           ← 404 (rare; API often returns 200 {} instead)

Auth errors deserve special handling — the Aranet API returns 401 as plain text (not JSON), so AranetAuthError doesn't carry a correlation ID. Validation errors are JSON with error[].id correlation tokens, preserved on AranetValidationError.correlation_id for support escalations.

Design

  • Async-first (aiohttp). Use as an async context manager (auto session) or inject an existing ClientSession — the HA-friendly pattern.
  • Typed: every response shape modelled as a dataclass with from_dict that ignores unknown fields, forward-compatible with new server fields.
  • Pagination hidden: iter_*_history() async generators follow next tokens transparently.
  • Retry/backoff on 5xx, 429, and transient network failures. Exponential backoff (1s, 2s, 4s, 8s) capped at 30 s; max 3 retries by default.
  • Polite-spacing floor (250 ms) between successive requests. The Aranet API has no documented rate limit, but we don't hammer.
  • Never logs the API key. Debug logs cover request method, path, status, and body size; the key is in headers only.

Standalone usage outside Home Assistant

The library has no HA dependencies and is fine to use in standalone Python scripts, FastAPI services, data-ingestion pipelines, etc.:

async with AranetCloudClient(api_key="...") as client:
    # Pull 24 hours of CO₂ readings for a single sensor
    readings = [
        r async for r in client.iter_measurements_history(
            sensor="4205836", metric="3", hours=24,
        )
    ]
    print(f"got {len(readings)} CO₂ samples")

Development

git clone https://github.com/jasonjhofmann/aranet-cloud
cd aranet-cloud
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest               # 23 tests, ~0.7s
ruff check .         # lint
mypy src             # type-check (strict)
python -m build      # build wheel + sdist

License

Apache 2.0

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

aranet_cloud-0.1.0.tar.gz (46.6 kB view details)

Uploaded Source

Built Distribution

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

aranet_cloud-0.1.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file aranet_cloud-0.1.0.tar.gz.

File metadata

  • Download URL: aranet_cloud-0.1.0.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for aranet_cloud-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad3fcdfa3393faf1ac65f72068141a8cd761937284634a2113e666e5e0b8da36
MD5 f53c88dfcc19a61500375fbb562fac7b
BLAKE2b-256 809b46204fe147942678b32c6062188fc805bc3867b4797fa8c7ef8314596d30

See more details on using hashes here.

File details

Details for the file aranet_cloud-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aranet_cloud-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for aranet_cloud-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a53562020c2b40b99a7e3eaf3ae001a9897499dca77f84ccd8fc9b193815032
MD5 f3f7a1990110325aa795e027a471d0e0
BLAKE2b-256 dc42f8da70b5bb32a1989071e288f801b78d901a63562cc31091065c4393e00f

See more details on using hashes here.

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