animedex.models.aggregate
Shared result envelope for multi-source aggregate commands.
Aggregate commands such as animedex season and animedex
schedule fan out to multiple upstream backends and may receive a
mix of successful rows and per-source failures. This module provides
the stable envelope shape those commands return: items contains
only rows from successful sources, while sources records one
status row per selected backend.
AggregateSourceStatus
- class animedex.models.aggregate.AggregateSourceStatus(*, backend: str, status: str, items: int = 0, reason: str | None = None, message: str | None = None, http_status: int | None = None, duration_ms: float = 0.0)[source]
Bases:
AnimedexModelStatus row for one backend inside an aggregate response.
- Variables:
backend (str) – Backend identifier, e.g.
"anilist".status (str) –
"ok"for a successful source,"failed"for a source that raised while the fan-out continued.items (int) – Number of successful rows contributed by this source.
reason (str or None) – Stable error reason when the source failed.
message (str or None) – Human-readable source failure message.
http_status (int or None) – HTTP status code when the failure exposed one.
duration_ms (float) – Wall-clock time spent in this source call.
AggregateResult
- class animedex.models.aggregate.AggregateResult(*, items: ~typing.List[~typing.Any] = <factory>, sources: ~typing.Dict[str, ~animedex.models.aggregate.AggregateSourceStatus] = <factory>, merge_diagnostics: ~typing.List[~typing.Dict[str, ~typing.Any]] = <factory>)[source]
Bases:
AnimedexModelEnvelope returned by multi-source aggregate commands.
The
itemslist preserves each backend’s rich model. Failures are deliberately not injected intoitems; they live only insourcesso a caller iterating over successful records never has to special-case failure sentinels.- Variables:
- items: List[Any]
- sources: Dict[str, AggregateSourceStatus]
- property failed_sources: Dict[str, AggregateSourceStatus]
Return the failed source statuses.
- Returns:
Mapping containing only failed sources.
- Return type:
ScheduleCalendarResult
- class animedex.models.aggregate.ScheduleCalendarResult(*, items: ~typing.List[~typing.Any] = <factory>, sources: ~typing.Dict[str, ~animedex.models.aggregate.AggregateSourceStatus] = <factory>, merge_diagnostics: ~typing.List[~typing.Dict[str, ~typing.Any]] = <factory>, timezone: str, window_start: ~datetime.date, window_end: ~datetime.date)[source]
Bases:
AggregateResultAggregate schedule envelope with display-time metadata.
The JSON renderer emits this as a normal structured aggregate result. The TTY renderer uses the timezone and date window fields to group schedule rows into a calendar-like view.
- Variables:
timezone (str) – IANA timezone name,
"UTC","local", or a fixed-offset value such as"+08:00".window_start (datetime.date) – Inclusive local date for the schedule window.
window_end (datetime.date) – Exclusive local date for the schedule window.
- window_start: date
- window_end: date
MergedAnime
- class animedex.models.aggregate.MergedAnime(*, title: ~animedex.models.anime.AnimeTitle, ids: ~typing.Dict[str, str] = <factory>, sources: ~typing.List[~animedex.models.common.SourceTag] = <factory>, records: ~typing.Dict[str, ~animedex.models.anime.Anime] = <factory>, core: ~typing.Dict[str, ~typing.Any] = <factory>, source_details: ~typing.Dict[str, ~typing.Dict[str, ~typing.Any]] = <factory>, source_payloads: ~typing.Dict[str, ~typing.Dict[str, ~typing.Any]] = <factory>, id_conflicts: ~typing.List[~typing.Dict[str, ~typing.Any]] = <factory>)[source]
Bases:
AnimedexModelOne anime entry merged across aggregate season sources.
- Variables:
title (AnimeTitle) – Canonical display title chosen from the contributing records.
sources (list[SourceTag]) – Provenance tags for every contributing backend.
records (dict[str, Anime]) – Per-backend common anime projections.
core (dict) – Compact merged summary. The JSON output keeps this next to the full per-backend records so consumers can read the resolved item without recomputing it.
source_details (dict[str, dict]) – Per-backend source-specific fields promoted from the contributing records.
source_payloads (dict[str, dict]) – Full per-backend payloads for JSON consumers that need the complete upstream row shape.
id_conflicts (list of dict) – External id conflicts found while building the merged id map.
- title: AnimeTitle
selftest
- animedex.models.aggregate.selftest() bool[source]
Smoke-test the aggregate envelope model.
The diagnostic runner invokes this to confirm that nested rich models can be carried through the aggregate JSON path and that the source-status helpers behave correctly.
- Returns:
Trueon success.- Return type: