animedex.backends.nekos.models
Rich nekos.best dataclasses (one per response shape).
nekos.best v2 has a tiny surface — three JSON-emitting endpoints — but each carries enough metadata to make the SFW image collection useful both as a CLI grab-bag and as a Python library lookup.
The two rich shapes pinned here are deliberately per-record, not per-endpoint:
NekosImage— one image / GIF record. Comes back from/<category>?amount=N(each row inresults) and from/search(each row inresults).NekosCategoryFormat— one{format, min, max}entry from/endpoints. The upstream emits a flat{<category>: {format, min, max}, ...}map, so the per-record type is what makes the lossless round-trip contract well-defined.
The NekosImage to_common() projects an upstream record
onto the cross-source ArtPost. The
projection is deterministic:
ratingis always"g"(nekos.best v2 has no NSFW tier).idis composed as"nekos:" + filename— nekos.best has no numeric ID column, but every URL ends in a stable filename, so the filename is the canonical identifier.tagscarries the upstream’sanime_name(when present) so a cross-source pipeline can match againstAnimeby show.
NekosImageDimensions
- class animedex.backends.nekos.models.NekosImageDimensions(*, width: int | None = None, height: int | None = None, **extra_data: Any)[source]
Bases:
BackendRichModeldimensionssub-block on aNekosImagerecord.- Variables:
NekosImage
- class animedex.backends.nekos.models.NekosImage(*, url: str, dimensions: NekosImageDimensions | None = None, anime_name: str | None = None, artist_name: str | None = None, artist_href: str | None = None, source_url: str | None = None, source_tag: SourceTag | None = None, **extra_data: Any)[source]
Bases:
BackendRichModelA single image / GIF record from nekos.best v2.
Every record exposes
urlanddimensions; the rest of the fields are best-effort attribution.anime_nameis set on anime-derived assets;artist_name/artist_href/source_urlare set on fan-art assets where the upstream knows the provenance.- Variables:
url (str) – Direct asset URL.
dimensions (NekosImageDimensions or None) –
{width, height}in pixels.anime_name (str or None) – Show name when the asset is anime-derived.
artist_name (str or None) – Artist attribution when the asset is fan art.
artist_href (str or None) – Artist’s profile / portfolio URL.
source_url (str or None) – Original source URL (pixiv / twitter / official site / etc.).
source_tag (SourceTag or None) – Provenance tag stamped by the high-level fetch helper.
- dimensions: NekosImageDimensions | None
- to_common() ArtPost[source]
Project this image record onto the cross-source
ArtPostshape.ratingis always"g"(nekos.best v2 is SFW-only).idderives from the URL’s filename, the only stable per-asset identifier nekos.best exposes. The upstream’sanime_nameis propagated intotagsso cross-source consumers can match on show without an extra round-trip.- Returns:
Cross-source projection.
- Return type:
NekosCategoryFormat
- class animedex.backends.nekos.models.NekosCategoryFormat(*, format: str | None = None, min: str | None = None, max: str | None = None, **extra_data: Any)[source]
Bases:
BackendRichModelPer-category format entry exposed by
/endpoints.Each category advertises a single asset format (
"png"or"gif") plus themin/maxfilename suffix range used by the/<category>/<filename>.<format>direct-asset retrieval. The flat/endpointspayload is a map from category name to one of these entries.- Variables:
selftest
- animedex.backends.nekos.models.selftest() bool[source]
Smoke-test the nekos models.
Validates a synthetic
NekosImageround-trips throughmodel_dump_json/model_validate_jsonand projects to a well-formedArtPost— pinning the SFW-onlyrating='g'invariant. Also validates a syntheticNekosCategoryFormat.- Returns:
Trueon success; raises on schema drift.- Return type: