Skip to main content

Python SDK for Nadeshiko API

Project description

This repository is still in WIP and not ready for production use

Nadeshiko Python SDK

PyPI

Python SDK for the Nadeshiko API

Quick Start

from nadeshiko import Nadeshiko, Environment
from nadeshiko.api.search import search

# Configure your client
client = Nadeshiko(
    api_key='your-api-key-here',
    base_url=Environment.PRODUCTION,  # or Environment.LOCAL, or custom URL
)

# Use API methods (names match OpenAPI operationIds)
result = search.sync(
    client=client,
    body={
        'query': '彼女',
        'limit': 10,
    },
)

if isinstance(result, Error):
    print(result.code, result.detail)
else:
    print(result.sentences)

API Methods

All methods are organized under nadeshiko.api.{module} and match the OpenAPI operationIds exactly:

You can check the full specification from the OpenAPI spec page.

Error Handling

All methods return a union type: Response | Error | None.

Check for errors:

from nadeshiko import Nadeshiko, Environment
from nadeshiko.api.search import search
from nadeshiko.models import Error

client = Nadeshiko(api_key='your-api-key', base_url=Environment.PRODUCTION)
result = search.sync(client=client, body={'query': '彼女'})

if isinstance(result, Error):
    # Error type is fully generated from OpenAPI spec
    print(result.code)    # e.g., 'RATE_LIMIT_EXCEEDED'
    print(result.title)   # e.g., 'Rate Limit Exceeded'
    print(result.detail)  # Detailed message
    print(result.status)  # HTTP status code
else:
    print(result.sentences)

In general, all SDK methods return typed errors generated from the OpenAPI spec:

class Error:
    code: str                 # e.g., 'RATE_LIMIT_EXCEEDED', 'AUTH_CREDENTIALS_INVALID'
    title: str                # Short summary
    detail: str               # Detailed explanation
    status: int               # HTTP status code
    type_: str | Unset        # URI to error documentation
    instance: str | Unset     # Trace ID
    errors: dict | Unset      # Validation errors

Handle each error independently based on the error code returned by the API.

from nadeshiko import Nadeshiko, Environment
from nadeshiko.api.search import search
from nadeshiko.models import Error

client = Nadeshiko(api_key='your-api-key')
result = search.sync(client=client, body={'query': '彼女'})

if isinstance(result, Error):
    # All error fields are typed
    match result.code:
        case 'RATE_LIMIT_EXCEEDED':
            print('Wait before retrying')
        case 'AUTH_CREDENTIALS_INVALID':
            print('Check your API key')
        case 'VALIDATION_FAILED':
            print('Field errors:', result.errors)
        case _:
            print(result.detail)

You can check the full list of errors codes for each endpoint from the OpenAPI spec page.

Type Support

All types are auto-generated from the OpenAPI spec.

from nadeshiko.models import (
    SearchRequest,
    SearchResponse,
    Sentence,
    MediaInfoData,
)

request: SearchRequest = {
    'query': '彼女',
    'limit': 10,
}

sentence: Sentence = {
    'basic_info': { # ... },
    'segment_info': { # ... },
    'media_info': { # ... },
}

Examples

See examples/usage.py for more usage examples.

References

Project details


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-0.2.0.tar.gz (110.4 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-0.2.0-py3-none-any.whl (161.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nadeshiko_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 110.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nadeshiko_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eff07179d1b9965a383c2d49001fdc3a5c4a41777158029a2002a8bcfc59c867
MD5 b62717bd94a02eb2481516f885dade1b
BLAKE2b-256 fd0da7180bff5c6466caf8b0d852f1eff033932ab857f7a6ce12be8b8dad405a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nadeshiko_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 161.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nadeshiko_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 859cde7c027c699b2cb9cb841c85d93ec7f5f3a6e7ee45e6f9ddeda37ebbd496
MD5 490cc90c52f75d49ef1c7abad5b757ae
BLAKE2b-256 891388451fdd00977062dd79edb25101a393b69223020f9ed172ce66f4af2b5f

See more details on using hashes here.

Supported by

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