Skip to main content

Async Python SDK for the Airbeld backend

Project description

Airbeld Python SDK

Async Python SDK for the Airbeld API, providing access to air quality devices and telemetry data.

If you want to contribute, read CONTRIBUTING and DEVELOPER.


Installation

# Using pip
pip install airbeld-api-sdk

# Using uv (recommended)
uv add airbeld-api-sdk

Examples

Environment Variables

Set these environment variables for the examples:

  • AIRBELD_API_BASE: API base URL (default: https://api.airbeld.com)
  • AIRBELD_API_TOKEN: JWT access token for authentication

Quickstart Example

import asyncio
import os
from datetime import datetime, timedelta, timezone
from airbeld import AirbeldClient

async def main():
    # Initialize client (JWT token obtained outside SDK)
    base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
    token = os.environ["AIRBELD_API_TOKEN"]
    
    async with AirbeldClient(token=token, base_url=base_url) as client:
        # Get all devices
        devices = await client.async_get_devices()
        print(f"Found {len(devices)} devices")
        
        if devices:
            device = devices[0]
            print(f"Device: {device.name} ({device.status})")
            
            # Get recent telemetry readings
            end = datetime.now(timezone.utc)
            start = end - timedelta(hours=1)
            
            readings = await client.async_get_readings_by_date(
                device_id=device.id,
                start=start,
                end=end,
                sensors=["temperature", "pm2p5"]  # Optional sensor filter
            )
            
            # Print latest temperature reading
            if "temperature" in readings.sensors:
                latest_temp = readings.get_latest_value("temperature")
                print(f"Latest temperature: {latest_temp}°C")

if __name__ == "__main__":
    asyncio.run(main())

Note: JWT token acquisition happens outside the SDK. The SDK only handles API requests with a ready token.

Authentication Options

The SDK supports two authentication paths depending on your use case:

Home Assistant Integration

For Home Assistant users, authentication is handled by the integration:

  • Home Assistant performs OAuth2 flow automatically
  • SDK receives a ready JWT token from the integration
  • See docs/home-assistant-auth.md for details

Standalone Applications (CLI, Scripts, etc.)

For standalone applications, use the built-in authentication:

import asyncio
import os
from airbeld import async_login, AirbeldClient

async def main():
    # Authenticate with email/password
    token_set = await async_login(
        base_url="https://api.airbeld.com",
        email=os.environ["AIRBELD_USER_EMAIL"],
        password=os.environ["AIRBELD_USER_PASSWORD"]
    )
    
    # Create client with access token
    async with AirbeldClient(token=token_set.access_token) as client:
        # List devices
        devices = await client.async_get_devices()
        print(f"Found {len(devices)} devices:")
        
        for device in devices:
            print(f"  - {device.name} ({device.status})")

if __name__ == "__main__":
    asyncio.run(main())

⚠️ Security Warning: Never commit real credentials or tokens to version control. Use environment variables or secure secret storage systems.

Token Management

For applications requiring token refresh or runtime token updates:

# Update token at runtime
client.set_token(new_token)

# Or use refresh token (if implemented)
new_token_set = await async_login(...)
client.set_token(new_token_set.access_token)

Development

Installation

Using uv (recommended):

# Clone the repository
git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
cd airbeld-api-sdk

# Create virtual environment and install dependencies
uv sync

Using pip:

# Clone the repository
git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
cd airbeld-api-sdk

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install package with dev dependencies
pip install -e ".[dev]"

Running Tests

# Using uv
uv run pytest

# Or with pip
pytest

Linting and Formatting

# Check code style
uv run ruff check .

# Format code
uv run ruff format .

# Or with pip
ruff check .
ruff format .

Type Checking

# Using uv
uv run mypy src

# Or with pip
mypy src

Building the Package

# Using uv
uv build

# Or with pip
python -m build

Resources

  • Contributing: See CONTRIBUTING.md for contribution guidelines
  • Changelog: See CHANGELOG.md for version history
  • License: This project is licensed under the MIT License - see LICENSE file for details

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

airbeld_api_sdk-0.1.1.tar.gz (42.1 kB view details)

Uploaded Source

Built Distribution

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

airbeld_api_sdk-0.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file airbeld_api_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: airbeld_api_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for airbeld_api_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6d9f4267e4079072682a280c90884bef9a44c2dd69e3be0b7397cbede848bdc5
MD5 ba496754b8593ae341f7340636fafd4e
BLAKE2b-256 8601ef66cb2a3133a275f3d0b79c312c3cc6c0debbfbe34245f3044fed62cce2

See more details on using hashes here.

File details

Details for the file airbeld_api_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for airbeld_api_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 727a8431bee5a9994ff4e6c6e26f1369efc79ab61f0d9b463544a025ec4e6dec
MD5 da9407d0d96d8143cece3a7db9e743d9
BLAKE2b-256 b8b47817450b63160b0d76cd4a054a8e39ea5e8da5f9b6fce3fbc6f9cb7611ee

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