Skip to content

HumanBaselines client

The HumanBaselines class is the entry point. Construct it once with your key, then call its compute and discovery methods.

python
from humanbaselines import HumanBaselines

hb = HumanBaselines(api_key="hbk_...")

Constructor

python
HumanBaselines(
    api_key: str | None = None,
    *,
    base_url: str = "https://humanbaselines.com",
    timeout: float = 30.0,
    max_retries: int = 2,
    session: requests.Session | None = None,
    config: dict | str | Path | None = None,
)
ArgumentDefaultNotes
api_key$HUMANBASELINES_API_KEYSent as the X-API-Key header. Raises ValueError if neither is set.
base_urlhttps://humanbaselines.comAPI host. Proxies /v1/*. Point at the Cloud Run URL for non-/v1 paths like health().
timeout30.0Per-request timeout, seconds.
max_retries2Automatic retries with exponential backoff on 502/503/504 (handles cold-start warm-up).
sessionnew requests.SessionBring your own session if you need custom transport.
configNoneA bound definition: a dict of county + filter fields, or a path to a JSON file from save_config. Validated here, so bad fields fail fast.

Methods

MethodPurpose
compute(...)Geofence (S2-cell) crash rate.
compute_route(...)Rate over interstate (route, milepost) segments.
compute_depot_route(...)Full depot-to-depot trip rate.
filters()Catalog of filters, options, and per-mode defaults.
regions()Regions available and the modes each supports.
manifest()Dataset metadata.
health()Service status (needs a Cloud Run base_url).
config() / changes() / with_config() / save_config() / from_config()Bound-definition helpers.

Lifecycle

HumanBaselines is a context manager; the underlying session closes on exit:

python
with HumanBaselines() as hb:
    print(hb.compute().rate)

Or call hb.close() explicitly. repr(hb) shows the base URL and any bound config.

Derived statistics only. Attribute every published figure. Maintained by Valgo.