Skip to content

oack-io/oack-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI version Python versions CI License: MPL 2.0 Checked with mypy Ruff

oack

Official Python client for the Oack monitoring API.

Installation

pip install oack

Or install from GitHub (always tracks the latest release):

pip install git+https://github.com/oack-io/oack-python.git@latest

Quick Start

Async (recommended)

from oack import AsyncOack

async with AsyncOack(api_key="sk-...") as client:
    teams = await client.teams.list()
    for team in teams:
        print(team.id, team.name)

Sync

from oack import Oack

with Oack(api_key="sk-...") as client:
    teams = client.teams.list()
    for team in teams:
        print(team.id, team.name)

Configuration

client = AsyncOack(
    api_key="sk-...",
    base_url="https://api.oack.io",  # default
    timeout=30.0,                     # seconds, default
    max_retries=2,                    # default
)

# Dynamic token (e.g. refreshable JWT)
client = AsyncOack(api_key_func=lambda: get_current_jwt())

Browser Login (Device Flow)

Authenticate via browser instead of a static API key. The JWT lives only in memory and disappears when the program exits.

from oack import Oack, device_flow_authenticate

# Opens your browser, waits for approval, returns JWT
token = device_flow_authenticate()

with Oack(api_key=token) as client:
    teams = client.teams.list()

Async version:

from oack import AsyncOack, async_device_flow_authenticate

token = await async_device_flow_authenticate()

async with AsyncOack(api_key=token) as client:
    teams = await client.teams.list()

Error Handling

from oack import AsyncOack, NotFoundError, RateLimitError, APIError

try:
    monitor = await client.monitors.get(team_id, monitor_id)
except NotFoundError:
    print("Monitor not found")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")

Resources

Resource Access Key Methods
Accounts client.accounts create, list, get, update, delete, restore, transfer
Teams client.teams create, list, get, update, delete, list_members, add_member
Monitors client.monitors create, list, get, update, delete, pause, unpause, duplicate, move
Probes client.probes list, get, get_details, download_pcap, aggregate
Alert Channels client.alert_channels create, list, get, update, delete, test
Metrics client.metrics get_monitor_metrics, get_expiration, list_timeline, chart events
Geo client.geo list_checkers, list_regions

Types

All response types are Pydantic v2 models with full IDE autocomplete:

from oack.types import Monitor, Team, Probe, CreateMonitorParams