Python client for the Harvest Forecast API — async and sync, with full coverage.
Project description
harvest-forecast-py
Python client for the Harvest Forecast API — async and sync, with full coverage.
Features
- Full API coverage — All resources, mutations, aggregates, and meta endpoints from the Forecast API
- Async and sync clients —
ForecastClientfor async/await code,SyncForecastClientfor synchronous code (generated viaunasync) - Fully typed — Pydantic v2 models for all responses, type hints throughout,
py.typedmarker included - Automatic retry — Configurable retry policy with exponential backoff and jitter for transient failures (429, 5xx, network errors)
- Pagination & windowing — Handles Forecast's pagination and the 2520-day assignment date range limit internally
- Structured exceptions — Typed exception hierarchy mapping HTTP status codes to specific errors
- Published on PyPI — Install with
piporuv, no build step required
Installation
# with pip
pip install harvest-forecast-py
# with uv
uv add harvest-forecast-py
Quick Start
Async
import asyncio
from datetime import date
from harvest_forecast import AssignmentFilter, ForecastClient
async def main() -> None:
async with ForecastClient(
access_token="your-personal-access-token",
account_id="123456",
user_agent="my-app (you@example.com)",
) as client:
people = await client.list_people()
for person in people:
print(person.id, person.first_name, person.last_name)
assignments = await client.list_assignments(
AssignmentFilter(
start_date=date(2026, 1, 1),
end_date=date(2026, 1, 31),
),
)
asyncio.run(main())
Sync
from datetime import date
from harvest_forecast import AssignmentFilter, SyncForecastClient
with SyncForecastClient(
access_token="your-personal-access-token",
account_id="123456",
user_agent="my-app (you@example.com)",
) as client:
people = client.list_people()
for person in people:
print(person.id, person.first_name, person.last_name)
assignments = client.list_assignments(
AssignmentFilter(
start_date=date(2026, 1, 1),
end_date=date(2026, 1, 31),
),
)
Authentication
The Harvest Forecast API uses three pieces of credentials, all passed to the client constructor:
| Parameter | Description |
|---|---|
access_token |
A personal access token. Create one at id.getharvest.com → Developer Tools → Personal Access Tokens. |
account_id |
Your Forecast account ID (a numeric string). Find it via client.whoami() or in the Forecast web app. |
user_agent |
A string identifying your application, including a contact email. Required by the Harvest API. Example: "my-app (you@example.com)". |
The client sends these as headers on every request:
Authorization: Bearer {access_token}Forecast-Account-ID: {account_id}User-Agent: {user_agent}Accept: application/json
The library does not load configuration from environment variables or files — pass credentials as plain constructor arguments so callers control their own config.
API Overview
Resources
| Resource | List | Get by ID | Create | Update | Delete |
|---|---|---|---|---|---|
| Assignments | list_assignments(filter) |
— | create_assignment(req) |
update_assignment(id, req) |
delete_assignment(id) |
| Clients | list_clients() |
— | — | — | — |
| Milestones | list_milestones() |
— | — | — | — |
| People | list_people() |
get_person(id) |
— | — | — |
| Placeholders | list_placeholders() |
get_placeholder(id) |
— | — | — |
| Projects | list_projects() |
get_project(id) |
— | — | — |
| Roles | list_roles() |
get_role(id) |
— | — | — |
| Repeated Assignment Sets | list_repeated_assignment_sets() |
get_repeated_assignment_set(id) |
— | — | — |
Meta Endpoints
| Method | Returns | Notes |
|---|---|---|
whoami() |
CurrentUser |
Returns account IDs — useful for discovering your Forecast account ID |
get_account() |
Account |
Account metadata, Harvest subdomain, billing status |
get_subscription() |
Subscription |
Billing/subscription details |
list_user_connections() |
list[UserConnection] |
Currently connected users |
Aggregates
| Method | Returns |
|---|---|
remaining_budgeted_hours() |
list[RemainingBudgetedHoursItem] |
future_scheduled_hours(from_date) |
list[FutureScheduledHoursItem] |
future_scheduled_hours_for_project(from_date, project_id) |
list[FutureScheduledHoursItem] |
assigned_people(start_date, end_date) |
dict[str, list[int]] |
project_heatmap(from, to, project_id, scale) |
list[ProjectHeatmapItem] |
person_heatmap(from, to, person_id, scale) |
list[PersonHeatmapItem] |
placeholder_heatmap(from, to, placeholder_id, scale) |
list[PlaceholderHeatmapItem] |
All methods return materialized objects — internal pagination and date windowing are hidden from callers.
Error Handling
The client maps HTTP status codes to a typed exception hierarchy before raising:
from harvest_forecast import (
ForecastClient,
ForecastAuthError,
ForecastNotFoundError,
ForecastRateLimitError,
ForecastServerError,
ForecastValidationError,
ForecastHTTPError,
)
async with ForecastClient(...) as client:
try:
person = await client.get_person(999999)
except ForecastAuthError:
# 401 or 403 — invalid token or account ID
...
except ForecastNotFoundError:
# 404 — resource doesn't exist
...
except ForecastRateLimitError as e:
# 429 — rate limited (e.retry_after may have the Retry-After value)
...
except ForecastServerError:
# 5xx — server-side error
...
except ForecastValidationError as e:
# API returned an error body (e.g. missing required fields)
print(e.response_body)
except ForecastHTTPError as e:
# Catch-all for other HTTP errors
print(e.status_code, e.response_body)
All HTTP exceptions carry status_code: int, response_body: str, and url: str.
Retry
The client retries transient failures (429, 5xx, network errors) automatically using a configurable RetryPolicy:
from harvest_forecast import ForecastClient, RetryPolicy
# Default: 6 attempts, exponential backoff (1s → 60s), 2s jitter
async with ForecastClient(
access_token="...",
account_id="...",
user_agent="...",
retry=RetryPolicy(),
) as client:
...
# Disable retries
async with ForecastClient(
...,
retry=RetryPolicy(max_attempts=1),
) as client:
...
Retry behavior:
- 429 / 5xx → retry with exponential backoff + jitter, honouring the
Retry-Afterheader - Network errors (
httpx.TransportError) → retry - 4xx (non-429) → raise immediately, no retry
- Hard cap on attempts to prevent infinite loops in cron-triggered jobs
See the retry guide for details.
Documentation
Full documentation is available at https://AZX-PBC-OSS.github.io/harvest-forecast-py/.
License
MIT — Copyright (c) 2025 AZX, PBC.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file harvest_forecast_py-0.1.0.tar.gz.
File metadata
- Download URL: harvest_forecast_py-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b5a767c64689381810961e3326a94da90d934bb66d27f917e9e497122d918b5
|
|
| MD5 |
1db1e40bec92e7807ec22e689455794e
|
|
| BLAKE2b-256 |
1edf84810682522051fe16ec5aac3e884802f5a835545dd18b56b90805782b0e
|
File details
Details for the file harvest_forecast_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: harvest_forecast_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56826f43aa383ca9e10d1ab282af8c8ffa708b0c79a15be8156ac85ea8eb9e6b
|
|
| MD5 |
2ebc316f71f5f896f03d3d2cd81fc35c
|
|
| BLAKE2b-256 |
e59f4683ee4f3aaccf57ea885a27c8c4ae55b3180537ae12963519e9cee154f8
|