Skip to main content

Python

pip install hometown-estimator

It needs Python 3.11 or newer.

Make an estimate​

import os

from hometown_estimator import Hometown

hometown = Hometown(os.environ["HOMETOWN_API_KEY"])

estimate = hometown.estimates.create({"input": {"text": "sandbox:priced"}})
print(estimate["status"], estimate["price"])

Objects are plain dicts with the keys of the API, typed for mypy and your editor in hometown_estimator.types. Every call that takes your key is a method on a resource: hometown.estimates.retrieve(estimate_id), hometown.customers.list(limit=20), hometown.webhook_endpoints.create({...}). Each takes timeout=. estimates.create, estimates.follow_up and customers.create also take your own idempotency_key=.

Catch errors​

from hometown_estimator import HometownError, InsufficientCreditsError

try:
hometown.estimates.create({"input": {"text": "Paint a 12 by 14 ft bedroom"}})
except InsufficientCreditsError:
... # buy credits in the dashboard
except HometownError as error:
print(error.code, error.request_id)

The class names follow the codes: rate_limited is RateLimitedError, validation_failed is ValidationFailedError. A request that never gets an answer raises APIConnectionError.

Check a webhook​

Pass the raw body, before any JSON parsing:

from hometown_estimator import verify_webhook

event = verify_webhook(request.body, request.headers.get("Hometown-Signature"), endpoint_secret)

It raises WebhookSignatureError when no signature matches or the delivery's timestamp is more than five minutes off.