Skip to content

kaloricketabulky.sdk.client

kaloricketabulky.sdk.client

Async read-only client for the kaloricketabulky.cz internal API.

KaloricketabulkyClient

KaloricketabulkyClient(
    *,
    base_url=DEFAULT_BASE_URL,
    client=None,
    timeout=DEFAULT_TIMEOUT,
)

Async client returning curated models. Call login before fetching data.

Source code in src/kaloricketabulky/sdk/client.py
def __init__(
    self,
    *,
    base_url: str = DEFAULT_BASE_URL,
    client: httpx.AsyncClient | None = None,
    timeout: float = DEFAULT_TIMEOUT,
) -> None:
    self._client = client if client is not None else httpx.AsyncClient(base_url=base_url, timeout=timeout)
    self._stack = AsyncExitStack()
    if client is None:
        # We created the client, so we close it on aclose(); a supplied one is left open.
        self._stack.push_async_callback(self._client.aclose)

login async

login(email, password)

Authenticate; the session cookies are stored on the underlying HTTP client.

Subsequent requests reuse them. If the session later expires, catch the error and call this again.

Source code in src/kaloricketabulky/sdk/client.py
async def login(self, email: str, password: str) -> None:
    """Authenticate; the session cookies are stored on the underlying HTTP client.

    Subsequent requests reuse them. If the session later expires, catch the error
    and call this again.
    """
    await auth.login(self._client, email, password)

aclose async

aclose()

Close the HTTP client if this instance created it; leave a supplied one open.

Source code in src/kaloricketabulky/sdk/client.py
async def aclose(self) -> None:
    """Close the HTTP client if this instance created it; leave a supplied one open."""
    await self._stack.aclose()

get_diary async

get_diary(day)

Fetch the diary (meals, activities, totals) for a day.

Source code in src/kaloricketabulky/sdk/client.py
async def get_diary(self, day: date) -> Diary:
    """Fetch the diary (meals, activities, totals) for a day."""
    return await self._get(f"/user/diary/{format_path_date(day)}/get", Diary)

get_tips async

get_tips(date_from, date_to)

Fetch analysis tips for a date range.

Source code in src/kaloricketabulky/sdk/client.py
async def get_tips(self, date_from: date, date_to: date) -> list[Tip]:
    """Fetch analysis tips for a date range."""
    path = f"/statistic/analysis/tips/{format_path_date(date_from)}/{format_path_date(date_to)}/get"
    return await self._get(path, list[Tip], params={"top": "true"})

get_streak async

get_streak(day)

Fetch the number of consecutive days tracked up to day.

Source code in src/kaloricketabulky/sdk/client.py
async def get_streak(self, day: date) -> int:
    """Fetch the number of consecutive days tracked up to `day`."""
    return await self._get("/user/streak", int, params={"date": format_query_date(day)})

get_diary_summary async

get_diary_summary(day)

Fetch the diary summary for a day.

Source code in src/kaloricketabulky/sdk/client.py
async def get_diary_summary(self, day: date) -> DiarySummary:
    """Fetch the diary summary for a day."""
    return await self._get(f"/user/diary/summary/{format_path_date(day)}/get", DiarySummary)

get_statistics_summary async

get_statistics_summary(day)

Fetch the statistics summary for a day.

Source code in src/kaloricketabulky/sdk/client.py
async def get_statistics_summary(self, day: date) -> StatisticsSummary:
    """Fetch the statistics summary for a day."""
    return await self._get(f"/statistic/summary/{format_path_date(day)}/get", StatisticsSummary)

get_snapshot async

get_snapshot(metric, date_from, date_to)

Fetch a single-series snapshot (energy, nutrients, drink, or weight).

metric excludes the optional series at the type level; use get_optional_snapshots for that.

Source code in src/kaloricketabulky/sdk/client.py
async def get_snapshot(self, metric: SingleSnapshotType, date_from: date, date_to: date) -> Snapshot:
    """Fetch a single-series snapshot (energy, nutrients, drink, or weight).

    `metric` excludes the optional series at the type level; use
    `get_optional_snapshots` for that.
    """
    path = f"/statistic/{metric.value}/{format_path_date(date_from)}/{format_path_date(date_to)}/get"
    return await self._get(path, Snapshot)

get_optional_snapshots async

get_optional_snapshots(date_from, date_to)

Fetch all optional (custom) metric snapshots for a date range.

Source code in src/kaloricketabulky/sdk/client.py
async def get_optional_snapshots(self, date_from: date, date_to: date) -> list[Snapshot]:
    """Fetch all optional (custom) metric snapshots for a date range."""
    path = f"/statistic/optional/{format_path_date(date_from)}/{format_path_date(date_to)}/get"
    return await self._get(path, list[Snapshot])