Skip to content

HumanBaselines client

Construct HumanBaselines 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, which covers cold-start warm-up.
sessionnew requests.SessionBring your own session if you need custom transport.
configNoneA bound definition: a dict of region plus 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_batch(...)Geofence rate across several regions in one request.
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, and 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.