Skip to main content
The AsyncDevHelm client provides the same methods as the sync client but returns awaitables for use with asyncio.

Initialize

import os
from devhelm import AsyncDevHelm

client = AsyncDevHelm(
    token=os.environ["DEVHELM_API_TOKEN"],
)
The async client accepts the same configuration options as Devhelm:
ParameterTypeDefaultDescription
tokenstrDEVHELM_API_TOKEN envAPI token
base_urlstrhttps://api.devhelm.ioAPI base URL
org_idstrDEVHELM_ORG_ID env or "1"Organization ID
timeoutfloat30.0Request timeout in seconds

Basic usage

import asyncio
from devhelm import AsyncDevHelm

async def main():
    client = AsyncDevHelm(token=os.environ["DEVHELM_API_TOKEN"])

    monitors = await client.monitors.list()
    for monitor in monitors:
        print(f"{monitor['name']}: {monitor['status']}")

asyncio.run(main())

Concurrent operations

The async client enables concurrent API calls:
import asyncio
from devhelm import AsyncDevHelm

async def check_all_monitors():
    client = AsyncDevHelm(token=os.environ["DEVHELM_API_TOKEN"])

    monitors = await client.monitors.list()

    tasks = [
        client.monitors.results(m["id"], limit=1)
        for m in monitors
    ]
    results = await asyncio.gather(*tasks)

    for monitor, result in zip(monitors, results):
        latest = result.data[0] if result.data else None
        status = f"{latest['responseTimeMs']}ms" if latest else "no data"
        print(f"{monitor['name']}: {status}")

asyncio.run(check_all_monitors())

Batch operations

Create multiple resources concurrently:
async def create_monitors(client, configs):
    tasks = [client.monitors.create(config) for config in configs]
    return await asyncio.gather(*tasks, return_exceptions=True)

async def main():
    client = AsyncDevHelm(token=os.environ["DEVHELM_API_TOKEN"])

    configs = [
        {"name": "API Health", "type": "HTTP", "config": {"url": "https://api.example.com/health"}, "frequencySeconds": 60},
        {"name": "Web Health", "type": "HTTP", "config": {"url": "https://example.com"}, "frequencySeconds": 300},
    ]

    results = await create_monitors(client, configs)
    for result in results:
        if isinstance(result, Exception):
            print(f"Failed: {result}")
        else:
            print(f"Created: {result['name']} (ID: {result['id']})")

asyncio.run(main())

Error handling

Error handling works the same as the sync client — DevhelmError and AuthError are raised as exceptions:
from devhelm import AsyncDevHelm, DevhelmError

async def safe_get(client, monitor_id):
    try:
        return await client.monitors.get(monitor_id)
    except DevhelmError as e:
        print(f"Error: {e.code}{e.message}")
        return None

When to use async

Use caseRecommended
Script that makes a few API callsSync Devhelm
Bulk operations (many creates/updates)Async AsyncDevHelm
Web app or API server handlerAsync AsyncDevHelm
Monitoring dashboard with parallel fetchesAsync AsyncDevHelm

Next steps

Client reference

Full method reference for all resources.

Error handling

Exception types and retry patterns.