DOCS / SDKS / PYTHON
VIEW RAW

Python SDK

Preview. The source lives at packages/sdk-py in the public repo. The PyPI package is not published yet; install from the repo or copy the snippet you need. All examples on this page work today against https://humanhours.dev/api/v1/*.

# Once the package ships:
pip install humanhours

# In the meantime:
git clone https://github.com/triadgit/agent-metrics
pip install -e ./agent-metrics/packages/sdk-py

60-second quickstart

from humanhours import Humanhours

hh = Humanhours(api_key="hh_live_...")

hh.track(
    agent_id="support-classifier",
    task_type="email_classification",
    outcome="success",
)

Decorator

from humanhours import Humanhours, track

hh = Humanhours(api_key="...", default_agent_id="support-classifier")

@track(hh, task_type="email_classification")
def classify(subject: str) -> str:
    ...

The decorator times the function, captures outcome="success" on return or outcome="failure" on raise, and reports automatically. Failures re-raise — your code keeps its normal control flow.

Ambient client

with Humanhours(api_key="...") as hh:
    @track(task_type="contract_clause_review", agent_id="legal-clause-reviewer")
    def review_clause(text):
        ...
    review_clause("...")

@track without client= picks up the active with scope. Useful when you can't pass the client through a deep call tree.

Reading numbers back

hh.summary(period="30d")
hh.agents()
hh.report("/time-saved", {"period": "30d", "group_by": "agent"})

Errors

from humanhours import HumanhoursError

try:
    hh.track(task_type="...", agent_id="...", outcome="success")
except HumanhoursError as e:
    if e.code == "unknown_task_type":
        ...
    raise

See also


Found a typo or want to suggest an edit? Email support@triadagency.ai.