Client¶
pyhellofresh.HelloFreshClient ¶
HelloFreshClient(
*,
session: ClientSession | None = None,
access_token: str | None = None,
refresh_token: str | None = None,
guest_token: str | None = DEFAULT_GUEST_TOKEN,
country: str = DEFAULT_COUNTRY,
locale: str = DEFAULT_LOCALE,
base_url: str = DEFAULT_BASE_URL,
request_timeout: float = 10.0,
)
Async Client for accessing HelloFresh APIs.
Supports dependency injection of an external aiohttp.ClientSession in compliance with Home Assistant's inject-websession quality rule.
Initialize the HelloFresh Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession | None
|
Optional externally managed aiohttp.ClientSession. |
None
|
access_token
|
str | None
|
Optional OAuth Bearer access token. |
None
|
refresh_token
|
str | None
|
Optional OAuth refresh token. |
None
|
guest_token
|
str | None
|
Optional guest token for unauthenticated gateway endpoints. |
DEFAULT_GUEST_TOKEN
|
country
|
str
|
ISO country code (default "GB"). |
DEFAULT_COUNTRY
|
locale
|
str
|
Language locale identifier (default "en-GB"). |
DEFAULT_LOCALE
|
base_url
|
str
|
Base URL for HelloFresh gateway (default "https://www.hellofresh.co.uk"). |
DEFAULT_BASE_URL
|
request_timeout
|
float
|
Timeout in seconds for HTTP requests (default 10.0). |
10.0
|
Source code in src/pyhellofresh/client.py
with_session
async
classmethod
¶
with_session(
*,
access_token: str | None = None,
refresh_token: str | None = None,
guest_token: str | None = DEFAULT_GUEST_TOKEN,
country: str = DEFAULT_COUNTRY,
locale: str = DEFAULT_LOCALE,
base_url: str = DEFAULT_BASE_URL,
request_timeout: float = 10.0,
) -> Self
Create a client instance with an internally managed aiohttp ClientSession.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str | None
|
Optional OAuth Bearer access token. |
None
|
refresh_token
|
str | None
|
Optional OAuth refresh token. |
None
|
guest_token
|
str | None
|
Optional guest token for unauthenticated gateway endpoints. |
DEFAULT_GUEST_TOKEN
|
country
|
str
|
ISO country code. |
DEFAULT_COUNTRY
|
locale
|
str
|
Language locale. |
DEFAULT_LOCALE
|
base_url
|
str
|
Base gateway URL. |
DEFAULT_BASE_URL
|
request_timeout
|
float
|
Request timeout in seconds. |
10.0
|
Returns:
| Type | Description |
|---|---|
Self
|
HelloFreshClient initialized with an active session. |
Source code in src/pyhellofresh/client.py
__aenter__
async
¶
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Async context manager exit point.
close
async
¶
Close the internally owned aiohttp session.
Note: If the session was injected externally, it will NOT be closed.
Source code in src/pyhellofresh/client.py
fetch_guest_token
async
¶
Dynamically fetch a fresh guest token from HelloFresh SSR HTML.
Returns:
| Type | Description |
|---|---|
str
|
The freshly extracted guest JWT access token. |
Raises:
| Type | Description |
|---|---|
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshAuthenticationError
|
If guest token cannot be parsed from SSR HTML. |
Source code in src/pyhellofresh/client.py
start_passwordless_login
async
¶
Start passwordless magic link login flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
User email address. |
required |
redirect_url
|
str | None
|
Optional custom redirect URL. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated public_id UUID string. |
Raises:
| Type | Description |
|---|---|
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshResponseError
|
On unexpected status code. |
Source code in src/pyhellofresh/client.py
finish_passwordless_login_from_url
async
¶
finish_passwordless_login_from_url(
url: str, public_id: str | None = None
) -> TokenResponse
Complete passwordless magic link login using a magic link URL or tracking link.
Resolves tracking redirects (e.g. click.link.hellofresh.co.uk), extracts the code, email, public_id, and redirect_url query parameters, and exchanges them for OAuth tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The full magic link URL received in email. |
required |
public_id
|
str | None
|
Optional fallback public_id if missing from URL query parameters. |
None
|
Returns:
| Type | Description |
|---|---|
TokenResponse
|
TokenResponse containing access_token and refresh_token. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If required parameters cannot be extracted. |
HelloFreshConnectionError
|
On network or redirection failure. |
Source code in src/pyhellofresh/client.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
finish_passwordless_login
async
¶
finish_passwordless_login(
code: str,
email: str,
public_id: str,
redirect_url: str | None = None,
) -> TokenResponse
Complete passwordless magic link login using the code from the magic link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The magic link token code. |
required |
email
|
str
|
User email address. |
required |
public_id
|
str
|
The public_id returned by start_passwordless_login. |
required |
redirect_url
|
str | None
|
Optional custom redirect URL. |
None
|
Returns:
| Type | Description |
|---|---|
TokenResponse
|
TokenResponse object containing access_token and refresh_token. |
Raises:
| Type | Description |
|---|---|
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshResponseError
|
On unexpected status code. |
Source code in src/pyhellofresh/client.py
refresh_access_token
async
¶
refresh_access_token(
refresh_token: str | None = None,
) -> TokenResponse
Refresh the access token using a refresh token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
refresh_token
|
str | None
|
Optional refresh token. Uses stored refresh_token if omitted. |
None
|
Returns:
| Type | Description |
|---|---|
TokenResponse
|
TokenResponse containing updated access_token and refresh_token. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If no refresh token is available. |
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshResponseError
|
On unexpected status code. |
Source code in src/pyhellofresh/client.py
get_profile
async
¶
get_profile() -> Profile
Fetch the current customer profile.
Returns:
| Type | Description |
|---|---|
Profile
|
Profile object containing household and dietary preferences. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If not authenticated or token invalid. |
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshResponseError
|
On unexpected status code. |
Source code in src/pyhellofresh/client.py
get_customer_info
async
¶
Fetch basic customer info including UUID, active subscription ID, and plan IDs.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing customer info. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_subscriptions
async
¶
Fetch customer active subscriptions.
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of subscription dictionaries. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_balance
async
¶
get_balance(
customer_id: str | None = None,
) -> AccountBalance
Fetch account balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
customer_id
|
str | None
|
Optional customer UUID string. If None, fetches customer info UUID. |
None
|
Returns:
| Type | Description |
|---|---|
AccountBalance
|
AccountBalance object. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_past_deliveries
async
¶
get_past_deliveries(
range_start: str | None = None,
range_end: str | None = None,
) -> PastDeliveries
Fetch customer deliveries schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
range_start
|
str | None
|
Optional ISO week string start (e.g. '2026-W30'). |
None
|
range_end
|
str | None
|
Optional ISO week string end (e.g. '2026-W40'). |
None
|
Returns:
| Type | Description |
|---|---|
PastDeliveries
|
PastDeliveries model containing past delivery items. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_menu
async
¶
get_menu(
week: str,
subscription_id: str | int | None = None,
product_sku: str | None = None,
) -> WeeklyMenu
Fetch weekly menu recipes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
week
|
str
|
Target delivery week identifier (e.g. '2026-W32'). |
required |
subscription_id
|
str | int | None
|
Optional customer subscription ID. |
None
|
product_sku
|
str | None
|
Optional product SKU (default auto-retrieved from customer info). |
None
|
Returns:
| Type | Description |
|---|---|
WeeklyMenu
|
WeeklyMenu model. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_meals_for_week_offset
async
¶
get_meals_for_week_offset(offset: int = 0) -> list[Meal]
Return the meals selected for a delivery week.
Offset 0 is the latest locked delivery: the newest scheduled week
whose cutoff has already passed. That is the box arriving now, rather
than the following week that is still open for selection. Positive
offsets move forward one ISO week at a time, and negative offsets move
backward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
int
|
Weeks after the latest locked delivery. |
0
|
Returns:
| Type | Description |
|---|---|
list[Meal]
|
Meals whose menu selection quantity is greater than zero. |
Raises:
| Type | Description |
|---|---|
HelloFreshError
|
If the delivery schedule has no usable week. |
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
get_recipe
async
¶
get_recipe(recipe_id: str) -> Recipe
Fetch details for a specific recipe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_id
|
str
|
Recipe identifier string. |
required |
Returns:
| Type | Description |
|---|---|
Recipe
|
Recipe model object. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
search_recipes
async
¶
search_recipes(
query: str, take: int = 20, skip: int = 0
) -> list[Recipe]
Search HelloFresh recipe catalog by keyword query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Keyword search string (e.g. "pasta", "chicken", "tacos"). |
required |
take
|
int
|
Maximum number of recipes to return (default 20). |
20
|
skip
|
int
|
Pagination offset index (default 0). |
0
|
Returns:
| Type | Description |
|---|---|
list[Recipe]
|
List of Recipe models matching search query. |
Raises:
| Type | Description |
|---|---|
HelloFreshConnectionError
|
On network issue or timeout. |
HelloFreshResponseError
|
On unexpected API error. |
Source code in src/pyhellofresh/client.py
get_cart_price
async
¶
get_cart_price(
week: str,
box_size: int = 2,
subscription_id: str | int | None = None,
product_sku: str | None = None,
products: list[dict[str, Any]] | None = None,
) -> CartPrice
Calculate cart price for a specific week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
week
|
str
|
Target delivery week identifier (e.g. '2026-W32'). |
required |
box_size
|
int
|
Number of meals / box size (default 2). |
2
|
subscription_id
|
str | int | None
|
Optional subscription ID. |
None
|
product_sku
|
str | None
|
Optional product SKU string. |
None
|
products
|
list[dict[str, Any]] | None
|
Optional list of product dictionaries. |
None
|
Returns:
| Type | Description |
|---|---|
CartPrice
|
CartPrice model. |
Raises:
| Type | Description |
|---|---|
HelloFreshAuthenticationError
|
If access_token is missing or expired. |
HelloFreshConnectionError
|
On network issue or timeout. |
Source code in src/pyhellofresh/client.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | |