Package Overview¶
The harvest_forecast package provides a fully-typed Python client for the Harvest Forecast API, with
both async and sync clients, automatic retry, pagination, and date-windowing.
Exports¶
The package exports the following public API:
Clients:
ForecastClient: Async client (alias forAsyncForecastClient)SyncForecastClient: Sync client
Schemas:
Assignment: Assignment resource modelAssignmentFilter: Filter for listing assignmentsAssignmentRequest: Payload for creating/updating assignmentsClient: Client resource modelMilestone: Milestone resource modelPerson: Person resource modelPlaceholder: Placeholder resource modelProject: Project resource modelRole: Role resource modelRepeatedAssignmentSet: Repeated assignment set modelCurrentUser: Authenticated user (fromwhoami())Account: Account metadata modelSubscription: Subscription/billing modelUserConnection: User connection modelRemainingBudgetedHoursItem: Remaining budgeted hours aggregateFutureScheduledHoursItem: Future scheduled hours aggregateProjectHeatmapItem: Project heatmap aggregatePersonHeatmapItem: Person heatmap aggregatePlaceholderHeatmapItem: Placeholder heatmap aggregateForecastModel: Base Pydantic model for all schemasWorkingDays: Working days configurationColorLabel: Color label modelSubscriptionAddress: Subscription addressSubscriptionCard: Subscription cardSubscriptionDiscounts: Subscription discountsSubscriptionIntervalUnitAmounts: Subscription interval amounts
Exceptions:
ForecastError: Base for all library exceptionsForecastHTTPError: Base for all HTTP errorsForecastAuthError: 401/403ForecastNotFoundError: 404ForecastRateLimitError: 429ForecastServerError: 5xxForecastValidationError: 400/422
Retry:
RetryPolicy: Retry configuration
Module Reference¶
harvest_forecast ¶
harvest_forecast — Python clients for the Harvest Forecast and Harvest APIs.
Canonical imports:
from harvest_forecast import ForecastClient, SyncForecastClient
from harvest_forecast import HarvestClient, SyncHarvestClient
from harvest_forecast import AssignmentFilter, AssignmentRequest
from harvest_forecast import RetryPolicy
from harvest_forecast import ForecastError, ForecastHTTPError
__all__
module-attribute
¶
__all__ = [
"Account",
"Assignment",
"AssignmentFilter",
"AssignmentRequest",
"Client",
"ColorLabel",
"CurrentUser",
"ForecastAuthError",
"ForecastClient",
"ForecastError",
"ForecastHTTPError",
"ForecastModel",
"ForecastNotFoundError",
"ForecastRateLimitError",
"ForecastServerError",
"ForecastValidationError",
"FutureScheduledHoursItem",
"HarvestClient",
"HarvestClientRef",
"HarvestCurrentUser",
"HarvestProject",
"HarvestProjectRef",
"HarvestTask",
"HarvestTaskRef",
"HarvestTimeEntry",
"HarvestUser",
"HarvestUserAssignment",
"HarvestUserRef",
"Milestone",
"Person",
"PersonHeatmapItem",
"Placeholder",
"PlaceholderHeatmapItem",
"Project",
"ProjectHeatmapItem",
"RemainingBudgetedHoursItem",
"RepeatedAssignmentSet",
"RetryPolicy",
"Role",
"Subscription",
"SubscriptionAddress",
"SubscriptionCard",
"SubscriptionDiscounts",
"SubscriptionIntervalUnitAmounts",
"SyncForecastClient",
"SyncHarvestClient",
"UserConnection",
"WorkingDays",
"__version__",
]
ForecastClient ¶
ForecastClient(
access_token: str,
account_id: str,
user_agent: str,
*,
base_url: str = "https://api.forecastapp.com",
timeout: float = 30.0,
retry: RetryPolicy | None = None,
)
Async client for the Harvest Forecast API.
Example
async with AsyncForecastClient( access_token="token", account_id="123", user_agent="my-app (you@example.com)", ) as client: people = await client.list_people()
Initialize the async Forecast client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Forecast personal access token. |
required |
account_id
|
str
|
Forecast account ID. |
required |
user_agent
|
str
|
User-Agent header value sent with every request. |
required |
base_url
|
str
|
Forecast API base URL. |
'https://api.forecastapp.com'
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
retry
|
RetryPolicy | None
|
Retry policy for transient failures. |
None
|
Source code in src/harvest_forecast/_async/client.py
__aenter__
async
¶
__aexit__
async
¶
aclose
async
¶
list_assignments
async
¶
List assignments, optionally filtered.
The Forecast API requires start_date and end_date parameters for the assignments endpoint. Large date ranges are automatically chunked into windows and results are deduplicated by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
AssignmentFilter | None
|
Filter criteria. Must include start_date and end_date. |
None
|
Returns:
| Type | Description |
|---|---|
list[Assignment]
|
List of Assignment objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If filter is None or lacks start_date/end_date. |
Source code in src/harvest_forecast/_async/client.py
list_clients
async
¶
List all clients in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Client]
|
List of Client objects. |
Source code in src/harvest_forecast/_async/client.py
list_milestones
async
¶
List all milestones in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Milestone]
|
List of Milestone objects. |
Source code in src/harvest_forecast/_async/client.py
list_people
async
¶
List all people being scheduled in Forecast.
Returns:
| Type | Description |
|---|---|
list[Person]
|
List of Person objects. |
Source code in src/harvest_forecast/_async/client.py
list_placeholders
async
¶
List all placeholders being scheduled in Forecast.
Returns:
| Type | Description |
|---|---|
list[Placeholder]
|
List of Placeholder objects. |
Source code in src/harvest_forecast/_async/client.py
list_projects
async
¶
List all projects in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Project]
|
List of Project objects. |
Source code in src/harvest_forecast/_async/client.py
list_roles
async
¶
list_repeated_assignment_sets
async
¶
List all repeated assignment sets in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[RepeatedAssignmentSet]
|
List of RepeatedAssignmentSet objects. |
Source code in src/harvest_forecast/_async/client.py
list_user_connections
async
¶
List all current user connections.
Returns:
| Type | Description |
|---|---|
list[UserConnection]
|
List of UserConnection objects. |
Source code in src/harvest_forecast/_async/client.py
get_person
async
¶
Retrieve a single person by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Person ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Person
|
Person object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_async/client.py
get_placeholder
async
¶
Retrieve a single placeholder by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Placeholder ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Placeholder
|
Placeholder object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_async/client.py
get_project
async
¶
Retrieve a single project by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Project ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Project
|
Project object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_async/client.py
get_role
async
¶
Retrieve a single role by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Role ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Role
|
Role object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_async/client.py
get_repeated_assignment_set
async
¶
Retrieve a single repeated assignment set by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Repeated assignment set ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
RepeatedAssignmentSet
|
RepeatedAssignmentSet object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_async/client.py
create_assignment
async
¶
Create a new assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req
|
AssignmentRequest
|
Assignment creation request payload. |
required |
Returns:
| Type | Description |
|---|---|
Assignment
|
The created Assignment object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If req.project_id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_async/client.py
update_assignment
async
¶
Update an existing assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Assignment ID (must be >= 1). |
required |
req
|
AssignmentRequest
|
Assignment update request payload. |
required |
Returns:
| Type | Description |
|---|---|
Assignment
|
The updated Assignment object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1 or req.project_id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_async/client.py
delete_assignment
async
¶
Delete an assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Assignment ID (must be >= 1). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_async/client.py
whoami
async
¶
get_account
async
¶
get_subscription
async
¶
Retrieve the Forecast subscription details.
Returns:
| Type | Description |
|---|---|
Subscription
|
Subscription object. |
Source code in src/harvest_forecast/_async/client.py
remaining_budgeted_hours
async
¶
Retrieve remaining budgeted hours for all projects.
Returns:
| Type | Description |
|---|---|
list[RemainingBudgetedHoursItem]
|
List of RemainingBudgetedHoursItem objects. |
Source code in src/harvest_forecast/_async/client.py
future_scheduled_hours
async
¶
Retrieve future scheduled hours starting from a date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
str | date
|
Starting date (ISO string or date object). |
required |
Returns:
| Type | Description |
|---|---|
list[FutureScheduledHoursItem]
|
List of FutureScheduledHoursItem objects. |
Source code in src/harvest_forecast/_async/client.py
future_scheduled_hours_for_project
async
¶
future_scheduled_hours_for_project(
from_date: str | date, project_id: int
) -> list[FutureScheduledHoursItem]
Retrieve future scheduled hours for a specific project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
str | date
|
Starting date (ISO string or date object). |
required |
project_id
|
int
|
Project ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[FutureScheduledHoursItem]
|
List of FutureScheduledHoursItem objects. |
Source code in src/harvest_forecast/_async/client.py
assigned_people
async
¶
Retrieve a mapping of project IDs to assigned person IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
str | date
|
Start date (ISO string or date object). |
required |
end_date
|
str | date
|
End date (ISO string or date object). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[int]]
|
Dict mapping project ID strings to lists of person IDs. |
Source code in src/harvest_forecast/_async/client.py
project_heatmap
async
¶
project_heatmap(
from_: str | date,
to: str | date,
project_id: int,
scale: str = "daily",
) -> list[ProjectHeatmapItem]
Retrieve a project heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
project_id
|
int
|
Project ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[ProjectHeatmapItem]
|
List of ProjectHeatmapItem objects. |
Source code in src/harvest_forecast/_async/client.py
person_heatmap
async
¶
person_heatmap(
from_: str | date,
to: str | date,
person_id: int,
scale: str = "daily",
) -> list[PersonHeatmapItem]
Retrieve a person heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
person_id
|
int
|
Person ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[PersonHeatmapItem]
|
List of PersonHeatmapItem objects. |
Source code in src/harvest_forecast/_async/client.py
placeholder_heatmap
async
¶
placeholder_heatmap(
from_: str | date,
to: str | date,
placeholder_id: int,
scale: str = "daily",
) -> list[PlaceholderHeatmapItem]
Retrieve a placeholder heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
placeholder_id
|
int
|
Placeholder ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[PlaceholderHeatmapItem]
|
List of PlaceholderHeatmapItem objects. |
Source code in src/harvest_forecast/_async/client.py
SyncHarvestClient ¶
SyncHarvestClient(
access_token: str,
account_id: str,
user_agent: str,
*,
base_url: str = "https://api.harvestapp.com/v2",
timeout: float = 30.0,
retry: RetryPolicy | None = None,
)
Sync client for the Harvest API v2.
Example
with SyncHarvestClient( access_token="token", account_id="123", user_agent="my-app (you@example.com)", ) as client: projects = client.list_projects()
Initialize the sync Harvest client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Harvest personal access token. |
required |
account_id
|
str
|
Harvest account ID. |
required |
user_agent
|
str
|
User-Agent header value sent with every request. |
required |
base_url
|
str
|
Harvest API base URL. |
'https://api.harvestapp.com/v2'
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
retry
|
RetryPolicy | None
|
Retry policy for transient failures. |
None
|
Source code in src/harvest_forecast/_harvest/client.py
__enter__ ¶
__exit__ ¶
close ¶
list_projects ¶
list_projects(
*,
is_active: bool | None = None,
client_id: int | None = None,
) -> list[HarvestProject]
List all projects in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
client_id
|
int | None
|
Filter by client ID. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestProject]
|
List of HarvestProject objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_users ¶
List all users in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestUser]
|
List of HarvestUser objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_clients ¶
List all clients in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestClient]
|
List of HarvestClient objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_tasks ¶
List all tasks in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestTask]
|
List of HarvestTask objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_time_entries ¶
list_time_entries(
*,
user_id: int | None = None,
project_id: int | None = None,
from_date: str | date | None = None,
to_date: str | date | None = None,
) -> list[HarvestTimeEntry]
List time entries, optionally filtered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int | None
|
Filter by user ID. |
None
|
project_id
|
int | None
|
Filter by project ID. |
None
|
from_date
|
str | date | None
|
Start date (ISO string or date object). |
None
|
to_date
|
str | date | None
|
End date (ISO string or date object). |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestTimeEntry]
|
List of HarvestTimeEntry objects. |
Source code in src/harvest_forecast/_harvest/client.py
create_time_entry ¶
create_time_entry(
*,
project_id: int,
task_id: int,
spent_date: str | date,
hours: float,
user_id: int | None = None,
notes: str | None = None,
) -> HarvestTimeEntry
Create a new time entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID to log time against. |
required |
task_id
|
int
|
Task ID to log time against. |
required |
spent_date
|
str | date
|
Date the time was spent (ISO string or date object). |
required |
hours
|
float
|
Number of hours to log. |
required |
user_id
|
int | None
|
User ID to log time for (admin-only; regular users cannot set this). |
None
|
notes
|
str | None
|
Optional notes for the time entry. |
None
|
Returns:
| Type | Description |
|---|---|
HarvestTimeEntry
|
The created HarvestTimeEntry object. |
Raises:
| Type | Description |
|---|---|
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_harvest/client.py
list_user_assignments ¶
List user assignments for a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID to list user assignments for. |
required |
Returns:
| Type | Description |
|---|---|
list[HarvestUserAssignment]
|
List of HarvestUserAssignment objects. |
Source code in src/harvest_forecast/_harvest/client.py
whoami ¶
Retrieve the current authenticated user.
Returns:
| Type | Description |
|---|---|
HarvestCurrentUser
|
HarvestCurrentUser object. |
HarvestClient ¶
HarvestClient(
access_token: str,
account_id: str,
user_agent: str,
*,
base_url: str = "https://api.harvestapp.com/v2",
timeout: float = 30.0,
retry: RetryPolicy | None = None,
)
Sync client for the Harvest API v2.
Example
with SyncHarvestClient( access_token="token", account_id="123", user_agent="my-app (you@example.com)", ) as client: projects = client.list_projects()
Initialize the sync Harvest client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Harvest personal access token. |
required |
account_id
|
str
|
Harvest account ID. |
required |
user_agent
|
str
|
User-Agent header value sent with every request. |
required |
base_url
|
str
|
Harvest API base URL. |
'https://api.harvestapp.com/v2'
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
retry
|
RetryPolicy | None
|
Retry policy for transient failures. |
None
|
Source code in src/harvest_forecast/_harvest/client.py
__enter__ ¶
__exit__ ¶
close ¶
list_projects ¶
list_projects(
*,
is_active: bool | None = None,
client_id: int | None = None,
) -> list[HarvestProject]
List all projects in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
client_id
|
int | None
|
Filter by client ID. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestProject]
|
List of HarvestProject objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_users ¶
List all users in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestUser]
|
List of HarvestUser objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_clients ¶
List all clients in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestClient]
|
List of HarvestClient objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_tasks ¶
List all tasks in the Harvest account.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_active
|
bool | None
|
Filter by active status. |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestTask]
|
List of HarvestTask objects. |
Source code in src/harvest_forecast/_harvest/client.py
list_time_entries ¶
list_time_entries(
*,
user_id: int | None = None,
project_id: int | None = None,
from_date: str | date | None = None,
to_date: str | date | None = None,
) -> list[HarvestTimeEntry]
List time entries, optionally filtered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int | None
|
Filter by user ID. |
None
|
project_id
|
int | None
|
Filter by project ID. |
None
|
from_date
|
str | date | None
|
Start date (ISO string or date object). |
None
|
to_date
|
str | date | None
|
End date (ISO string or date object). |
None
|
Returns:
| Type | Description |
|---|---|
list[HarvestTimeEntry]
|
List of HarvestTimeEntry objects. |
Source code in src/harvest_forecast/_harvest/client.py
create_time_entry ¶
create_time_entry(
*,
project_id: int,
task_id: int,
spent_date: str | date,
hours: float,
user_id: int | None = None,
notes: str | None = None,
) -> HarvestTimeEntry
Create a new time entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID to log time against. |
required |
task_id
|
int
|
Task ID to log time against. |
required |
spent_date
|
str | date
|
Date the time was spent (ISO string or date object). |
required |
hours
|
float
|
Number of hours to log. |
required |
user_id
|
int | None
|
User ID to log time for (admin-only; regular users cannot set this). |
None
|
notes
|
str | None
|
Optional notes for the time entry. |
None
|
Returns:
| Type | Description |
|---|---|
HarvestTimeEntry
|
The created HarvestTimeEntry object. |
Raises:
| Type | Description |
|---|---|
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_harvest/client.py
list_user_assignments ¶
List user assignments for a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID to list user assignments for. |
required |
Returns:
| Type | Description |
|---|---|
list[HarvestUserAssignment]
|
List of HarvestUserAssignment objects. |
Source code in src/harvest_forecast/_harvest/client.py
whoami ¶
Retrieve the current authenticated user.
Returns:
| Type | Description |
|---|---|
HarvestCurrentUser
|
HarvestCurrentUser object. |
SyncForecastClient ¶
SyncForecastClient(
access_token: str,
account_id: str,
user_agent: str,
*,
base_url: str = "https://api.forecastapp.com",
timeout: float = 30.0,
retry: RetryPolicy | None = None,
)
Async client for the Harvest Forecast API.
Example
async with AsyncForecastClient( access_token="token", account_id="123", user_agent="my-app (you@example.com)", ) as client: people = await client.list_people()
Initialize the async Forecast client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
Forecast personal access token. |
required |
account_id
|
str
|
Forecast account ID. |
required |
user_agent
|
str
|
User-Agent header value sent with every request. |
required |
base_url
|
str
|
Forecast API base URL. |
'https://api.forecastapp.com'
|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
retry
|
RetryPolicy | None
|
Retry policy for transient failures. |
None
|
Source code in src/harvest_forecast/_sync/client.py
__enter__ ¶
__exit__ ¶
close ¶
list_assignments ¶
List assignments, optionally filtered.
The Forecast API requires start_date and end_date parameters for the assignments endpoint. Large date ranges are automatically chunked into windows and results are deduplicated by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
AssignmentFilter | None
|
Filter criteria. Must include start_date and end_date. |
None
|
Returns:
| Type | Description |
|---|---|
list[Assignment]
|
List of Assignment objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If filter is None or lacks start_date/end_date. |
Source code in src/harvest_forecast/_sync/client.py
list_clients ¶
List all clients in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Client]
|
List of Client objects. |
list_milestones ¶
List all milestones in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Milestone]
|
List of Milestone objects. |
Source code in src/harvest_forecast/_sync/client.py
list_people ¶
List all people being scheduled in Forecast.
Returns:
| Type | Description |
|---|---|
list[Person]
|
List of Person objects. |
list_placeholders ¶
List all placeholders being scheduled in Forecast.
Returns:
| Type | Description |
|---|---|
list[Placeholder]
|
List of Placeholder objects. |
Source code in src/harvest_forecast/_sync/client.py
list_projects ¶
List all projects in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[Project]
|
List of Project objects. |
Source code in src/harvest_forecast/_sync/client.py
list_repeated_assignment_sets ¶
List all repeated assignment sets in the Forecast account.
Returns:
| Type | Description |
|---|---|
list[RepeatedAssignmentSet]
|
List of RepeatedAssignmentSet objects. |
Source code in src/harvest_forecast/_sync/client.py
list_user_connections ¶
List all current user connections.
Returns:
| Type | Description |
|---|---|
list[UserConnection]
|
List of UserConnection objects. |
Source code in src/harvest_forecast/_sync/client.py
get_person ¶
Retrieve a single person by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Person ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Person
|
Person object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_sync/client.py
get_placeholder ¶
Retrieve a single placeholder by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Placeholder ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Placeholder
|
Placeholder object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_sync/client.py
get_project ¶
Retrieve a single project by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Project ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Project
|
Project object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_sync/client.py
get_role ¶
Retrieve a single role by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Role ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
Role
|
Role object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_sync/client.py
get_repeated_assignment_set ¶
Retrieve a single repeated assignment set by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Repeated assignment set ID (must be >= 1). |
required |
Returns:
| Type | Description |
|---|---|
RepeatedAssignmentSet
|
RepeatedAssignmentSet object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors (e.g. 404). |
Source code in src/harvest_forecast/_sync/client.py
create_assignment ¶
Create a new assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req
|
AssignmentRequest
|
Assignment creation request payload. |
required |
Returns:
| Type | Description |
|---|---|
Assignment
|
The created Assignment object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If req.project_id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_sync/client.py
update_assignment ¶
Update an existing assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Assignment ID (must be >= 1). |
required |
req
|
AssignmentRequest
|
Assignment update request payload. |
required |
Returns:
| Type | Description |
|---|---|
Assignment
|
The updated Assignment object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1 or req.project_id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_sync/client.py
delete_assignment ¶
Delete an assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int
|
Assignment ID (must be >= 1). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id < 1. |
ForecastHTTPError
|
On HTTP errors. |
Source code in src/harvest_forecast/_sync/client.py
whoami ¶
get_account ¶
get_subscription ¶
Retrieve the Forecast subscription details.
Returns:
| Type | Description |
|---|---|
Subscription
|
Subscription object. |
Source code in src/harvest_forecast/_sync/client.py
remaining_budgeted_hours ¶
Retrieve remaining budgeted hours for all projects.
Returns:
| Type | Description |
|---|---|
list[RemainingBudgetedHoursItem]
|
List of RemainingBudgetedHoursItem objects. |
Source code in src/harvest_forecast/_sync/client.py
future_scheduled_hours ¶
Retrieve future scheduled hours starting from a date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
str | date
|
Starting date (ISO string or date object). |
required |
Returns:
| Type | Description |
|---|---|
list[FutureScheduledHoursItem]
|
List of FutureScheduledHoursItem objects. |
Source code in src/harvest_forecast/_sync/client.py
future_scheduled_hours_for_project ¶
future_scheduled_hours_for_project(
from_date: str | date, project_id: int
) -> list[FutureScheduledHoursItem]
Retrieve future scheduled hours for a specific project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_date
|
str | date
|
Starting date (ISO string or date object). |
required |
project_id
|
int
|
Project ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[FutureScheduledHoursItem]
|
List of FutureScheduledHoursItem objects. |
Source code in src/harvest_forecast/_sync/client.py
assigned_people ¶
Retrieve a mapping of project IDs to assigned person IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
str | date
|
Start date (ISO string or date object). |
required |
end_date
|
str | date
|
End date (ISO string or date object). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[int]]
|
Dict mapping project ID strings to lists of person IDs. |
Source code in src/harvest_forecast/_sync/client.py
project_heatmap ¶
project_heatmap(
from_: str | date,
to: str | date,
project_id: int,
scale: str = "daily",
) -> list[ProjectHeatmapItem]
Retrieve a project heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
project_id
|
int
|
Project ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[ProjectHeatmapItem]
|
List of ProjectHeatmapItem objects. |
Source code in src/harvest_forecast/_sync/client.py
person_heatmap ¶
person_heatmap(
from_: str | date,
to: str | date,
person_id: int,
scale: str = "daily",
) -> list[PersonHeatmapItem]
Retrieve a person heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
person_id
|
int
|
Person ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[PersonHeatmapItem]
|
List of PersonHeatmapItem objects. |
Source code in src/harvest_forecast/_sync/client.py
placeholder_heatmap ¶
placeholder_heatmap(
from_: str | date,
to: str | date,
placeholder_id: int,
scale: str = "daily",
) -> list[PlaceholderHeatmapItem]
Retrieve a placeholder heatmap for a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_
|
str | date
|
Start date (ISO string or date object). |
required |
to
|
str | date
|
End date (ISO string or date object). |
required |
placeholder_id
|
int
|
Placeholder ID. |
required |
scale
|
str
|
Time scale (e.g. "daily", "weekly"). |
'daily'
|
Returns:
| Type | Description |
|---|---|
list[PlaceholderHeatmapItem]
|
List of PlaceholderHeatmapItem objects. |
Source code in src/harvest_forecast/_sync/client.py
ForecastAuthError ¶
Bases: ForecastHTTPError
401 or 403 — authentication or authorization failure.
Source code in src/harvest_forecast/exceptions.py
ForecastError ¶
Bases: Exception
Base for all exceptions raised by harvest_forecast.
ForecastHTTPError ¶
Bases: ForecastError
HTTP error from the Forecast API.
Carries status_code, response_body, and url. Subclasses map specific status-code ranges; this class serves as the catch-all for unrecognised codes and as the base for all HTTP exceptions.
Source code in src/harvest_forecast/exceptions.py
from_response
classmethod
¶
Source code in src/harvest_forecast/exceptions.py
ForecastNotFoundError ¶
Bases: ForecastHTTPError
404 — resource not found.
Source code in src/harvest_forecast/exceptions.py
ForecastRateLimitError ¶
ForecastRateLimitError(
status_code: int,
response_body: str,
url: str,
*,
retry_after: float | None = None,
)
Bases: ForecastHTTPError
429 — rate limited. Carries retry_after from the Retry-After header.
Source code in src/harvest_forecast/exceptions.py
ForecastServerError ¶
ForecastValidationError ¶
Bases: ForecastHTTPError
400 or 422 — API returned a validation error body.
Source code in src/harvest_forecast/exceptions.py
RetryPolicy
dataclass
¶
RetryPolicy(
max_attempts: int = 6,
initial_seconds: float = 1.0,
max_seconds: float = 60.0,
jitter_seconds: float = 2.0,
)
How the Forecast client handles transient failures.
no_wait
classmethod
¶
fast_test
classmethod
¶
Test-friendly: zero backoff, configurable attempt count.
Source code in src/harvest_forecast/retry.py
wait ¶
Source code in src/harvest_forecast/retry.py
Account ¶
Bases: ForecastModel
color_labels
class-attribute
instance-attribute
¶
Assignment ¶
Bases: ForecastModel
AssignmentFilter
dataclass
¶
AssignmentFilter(
project_id: int | None = None,
person_id: int | None = None,
start_date: date | None = None,
end_date: date | None = None,
repeated_assignment_set_id: int | None = None,
state: str | None = None,
)
AssignmentRequest
dataclass
¶
AssignmentRequest(
start_date: date,
end_date: date,
project_id: int,
person_id: int,
allocation: int | None = None,
notes: str | None = None,
placeholder_id: int | None = None,
repeated_assignment_set_id: int | None = None,
active_on_days_off: bool = False,
harvest_project_task_id: int | None = None,
)
repeated_assignment_set_id
class-attribute
instance-attribute
¶
harvest_project_task_id
class-attribute
instance-attribute
¶
to_payload ¶
Source code in src/harvest_forecast/schemas.py
Client ¶
Bases: ForecastModel
ColorLabel ¶
Bases: ForecastModel
CurrentUser ¶
Bases: ForecastModel
ForecastModel ¶
Bases: BaseModel
model_config
class-attribute
instance-attribute
¶
model_config = ConfigDict(
extra="allow",
populate_by_name=True,
str_strip_whitespace=True,
frozen=True,
)
FutureScheduledHoursItem ¶
Bases: ForecastModel
HarvestClientRef ¶
Bases: ForecastModel
HarvestCurrentUser ¶
Bases: ForecastModel
can_see_project_billable_rates
class-attribute
instance-attribute
¶
HarvestProject ¶
Bases: ForecastModel
HarvestProjectRef ¶
Bases: ForecastModel
HarvestTask ¶
Bases: ForecastModel
HarvestTaskRef ¶
Bases: ForecastModel
HarvestTimeEntry ¶
Bases: ForecastModel
HarvestUser ¶
Bases: ForecastModel
HarvestUserAssignment ¶
Bases: ForecastModel
HarvestUserRef ¶
Bases: ForecastModel
Milestone ¶
Bases: ForecastModel
Person ¶
Bases: ForecastModel
personal_feed_token_id
class-attribute
instance-attribute
¶
PersonHeatmapItem ¶
Bases: ForecastModel
Placeholder ¶
Bases: ForecastModel
PlaceholderHeatmapItem ¶
Bases: ForecastModel
Project ¶
Bases: ForecastModel
ProjectHeatmapItem ¶
Bases: ForecastModel
RemainingBudgetedHoursItem ¶
Bases: ForecastModel
RepeatedAssignmentSet ¶
Bases: ForecastModel
assignment_ids
class-attribute
instance-attribute
¶
Role ¶
Bases: ForecastModel
Subscription ¶
Bases: ForecastModel
SubscriptionAddress ¶
Bases: ForecastModel
SubscriptionCard ¶
Bases: ForecastModel
SubscriptionDiscounts ¶
Bases: ForecastModel
SubscriptionIntervalUnitAmounts ¶
Bases: ForecastModel
UserConnection ¶
Bases: ForecastModel
WorkingDays ¶
Bases: ForecastModel