Python SDK for Nadeshiko API
Project description
This repository is still in WIP and not ready for production use
Nadeshiko Python SDK
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nadeshiko_sdk-0.1.0.tar.gz.
File metadata
- Download URL: nadeshiko_sdk-0.1.0.tar.gz
- Upload date:
- Size: 72.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fbe13b1fcdb10592d89cd9e0cd3a923e4268f5c9b24cf20a2cc89b48c355a6e
|
|
| MD5 |
f78ea40b1368b52374f0133488425418
|
|
| BLAKE2b-256 |
5da6b487c87d8f6abbf9a3193c42f038adae5dab623b83ef294f7f8390d7cc05
|
File details
Details for the file nadeshiko_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nadeshiko_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 161.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cda07f08cbca5ba7bf3e0918aabd10bd5ccd43f90131fc5692c15384c748a56
|
|
| MD5 |
cb7e6d4a41bd3870d9ee01b6d20dccd5
|
|
| BLAKE2b-256 |
02f8c2b0d9f69047606230808b1601b319961de9c23b0a003fe56bed5f515b31
|