Skip to main content

Nadeshiko SDK

Python SDK for the Nadeshiko API. Full API reference at nadeshiko.co/docs/api.

Install

pip install nadeshiko-sdk

Quick start

from nadeshiko import Nadeshiko
from nadeshiko.models import SearchQuery

client = Nadeshiko(
    api_key=os.environ["NADESHIKO_API_KEY"],
)

data = client.search(query=SearchQuery(search="彼女"))
print(data.segments)
# [
#   Segment(
#     segment_public_id="xK9mP2nQwR4t",
#     media_public_id="steins-gate",
#     episode=1,
#     start_time_ms=62340,
#     end_time_ms=65180,
#     text_ja=SegmentTextJa(content="彼女に会いたい", ...),
#     text_en=SegmentTextEn(content="I want to see her", ...),
#     urls=SegmentUrls(
#       image_url="https://...",
#       audio_url="https://...",
#       video_url="https://...",
#     ),
#   ),
#   # ...
# ]

Methods return data directly and accept model objects — pass SearchQuery, SearchFilters, and other model instances directly.

Authentication

Pass your API key to Nadeshiko. It is sent as Authorization: Bearer <api_key> on every request.

client = Nadeshiko(
    api_key=os.environ["NADESHIKO_API_KEY"],
    base_url="PRODUCTION",  # "LOCAL" | "DEVELOPMENT" | "STAGING" | "PRODUCTION" | custom URL
    headers={"User-Agent": "MyApp/1.0"},
)

Model objects

All methods accept model objects — body fields are passed as SearchQuery, SearchFilters, and other model instances:

from nadeshiko.models import SearchQuery, SearchFilters, ContentRating

# POST endpoints — body models
result = client.search(
    query=SearchQuery(search="猫"),
    filters=SearchFilters(content_rating=[ContentRating.SAFE]),
)

# GET with query params — as keyword arguments
media_list = client.list_media(query="naruto", category="ANIME")

# GET with path params — as keyword arguments or positional
collection = client.get_collection("collection-public-id")
episode = client.get_episode(media_public_id="abc", episode_number=5)

Single-path-param endpoints also accept the ID as a plain string:

media = client.get_media("some-public-id")
segment = client.get_segment("some-uuid")
context = client.get_segment_context("some-uuid")

Available endpoints

Search

Method Description
search(params?) Search segments by query, with filters and sorting
get_search_stats(params?) Category counts and media list for filter UI
search_words(params) Look up multiple words and get match counts per media
search_media(params) Find media by name (autocomplete)

Stats

Method Description
get_stats_overview() Corpus-wide stats: segment count, media count, coverage tiers

Media

Method Description
list_media(params?) Browse the media catalog
get_media(id) Get a single media entry by public ID
list_episodes(params) List episodes for a media entry
get_episode(params) Get a single episode
get_segment(id) Get a single segment by UUID
get_segment_context(id) Get segments surrounding a given segment

User

Method Description
get_me() Current user profile and API quota
list_user_activity(params?) Activity history (searches, plays, exports)
get_user_activity_heatmap(params?) Daily activity counts for a heatmap
get_user_activity_stats(params?) Aggregate stats over a date range
list_excluded_media() Media hidden from search results
add_excluded_media(params) Hide a media entry from search results
remove_excluded_media(id) Un-hide a media entry

Collections

Method Description
list_collections(params?) List your saved collections
create_collection(params) Create a new collection
get_collection(id) Get a collection and its segments
delete_collection(id) Delete a collection
add_segment_to_collection(params) Add a segment to a collection
search_collection_segments(params) Search within a collection
remove_segment_from_collection(params) Remove a segment from a collection

Error handling

Errors throw a NadeshikoError. A proper Exception subclass with all RFC 7807 Problem Details fields.

from nadeshiko import NadeshikoError
from nadeshiko.models import SearchQuery

try:
    data = client.search(query=SearchQuery(search="食べる"))
    print(data.segments)
except NadeshikoError as err:
    match err.code:
        case "VALIDATION_FAILED":
            print("Validation failed:", err.detail)
            for field, msg in (err.errors or {}).items():
                print(f"  {field}: {msg}")
        case "AUTH_CREDENTIALS_REQUIRED" | "AUTH_CREDENTIALS_INVALID":
            print("Authentication failed:", err.detail)
        case "RATE_LIMIT_EXCEEDED":
            print("Rate limited - slow down")
        case "QUOTA_EXCEEDED":
            print("Monthly quota exhausted")
        case "INTERNAL_SERVER_EXCEPTION":
            print("Server error, trace ID:", err.trace_id)

NadeshikoError fields:

Field Type Description
code str Machine-readable error code
title str Short summary
detail str Human-readable explanation
status int HTTP status code
trace_id str | None Trace ID - include when reporting issues
errors dict[str, object] | None Per-field messages (VALIDATION_FAILED only)

Opt out of throwing per-call

Pass throw_on_error=False to get a response object instead of throwing:

from nadeshiko.models import SearchQuery

result = client.search(
    throw_on_error=False,
    query=SearchQuery(search="猫"),
)

if result.error is not None:
    print(result.error)
else:
    print(result.data.segments)

Retry and timeout

The client retries automatically on network errors and 408 / 429 / 500 / 502 / 503 / 504 responses. 429 responses with a Retry-After header are respected.

from nadeshiko import Nadeshiko, RetryOptions

client = Nadeshiko(
    api_key=os.environ["NADESHIKO_API_KEY"],
    retry_options=RetryOptions(
        max_retries=3,   # default: 2
        initial_delay=1, # default: 0.5 - doubles with each attempt
        max_delay=30,    # default: 30
        timeout=10,      # per-attempt timeout in seconds (default: none)
    ),
)

Pagination

Paginated endpoints have an iter_* method that returns an iterator over individual items:

from nadeshiko.models import SearchQuery

for segment in client.iter_search(
    query=SearchQuery(search="猫"),
):
    print(segment.text_ja.content)

for media in client.iter_list_media():
    print(media.name_en)

For manual page-by-page control, use the cursor field:

from nadeshiko.models import SearchQuery

cursor: str | None = None

while True:
    data = client.search(
        query=SearchQuery(search="犬"),
        take=10,
        cursor=cursor,
    )

    for segment in data.segments:
        print(segment.text_ja.content)

    if not data.pagination.has_more or data.pagination.cursor is None:
        break

    cursor = data.pagination.cursor

See examples/examples.py for more usage patterns.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nadeshiko_sdk-2.4.7.tar.gz (102.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nadeshiko_sdk-2.4.7-py3-none-any.whl (287.8 kB view details)

Uploaded Python 3

File details

Details for the file nadeshiko_sdk-2.4.7.tar.gz.

File metadata

  • Download URL: nadeshiko_sdk-2.4.7.tar.gz
  • Upload date:
  • Size: 102.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nadeshiko_sdk-2.4.7.tar.gz
Algorithm Hash digest
SHA256 213c93c6519d1586287e8efbc97667590e0bc4388a764cc8c04e20115b2371bf
MD5 a5c4ad3dbd2b2b85efd8fb60b8605140
BLAKE2b-256 95aebc7c7f86eb8c36c49dd2ac3b117e384dad0aabbd1db14659b6e4f8838902

See more details on using hashes here.

Provenance

The following attestation bundles were made for nadeshiko_sdk-2.4.7.tar.gz:

Publisher: release.yml on BrigadaSOS/nadeshiko-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nadeshiko_sdk-2.4.7-py3-none-any.whl.

File metadata

  • Download URL: nadeshiko_sdk-2.4.7-py3-none-any.whl
  • Upload date:
  • Size: 287.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nadeshiko_sdk-2.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 830468304397f9c481597f3423f427ccc2b42607bdd0a466ff5b54b0f0cbd896
MD5 12bbb119c0485dc00af14dcd05d3d985
BLAKE2b-256 074e8344ee1435d5db11c9bdebeee4ee9f1bdb4f4a615e3cb7b5b75e5cb6f4f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for nadeshiko_sdk-2.4.7-py3-none-any.whl:

Publisher: release.yml on BrigadaSOS/nadeshiko-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.4.7 This release

2 files

2.4.6

2 files

2.4.5

2 files

2.4.4

2 files

2.4.3

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.7

2 files

2.3.6

2 files

2.3.5

2 files

2.3.4

2 files

2.3.3

2 files

2.3.1

2 files

2.3.0

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.0.7

2 files

2.0.6

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page