Client¶
client
¶
Client
¶
Client(
token: str | None = None,
*,
base_url: str = PROD_BASE_URL,
timeout: float = DEFAULT_TIMEOUT,
user_agent: str = DEFAULT_USER_AGENT,
retry: RetryConfig | None = None,
http_client: Client | None = None,
cache_ttl: float | None = None,
cache_maxsize: int = 128,
)
Synchronous VNDB Kana API client.
The client owns an HTTP transport and exposes one typed query resource per
entity (vn, release, producer, character, staff, tag,
trait, quote, ulist), plus the simple GET endpoints and user-list
write helpers. Use it as a context manager so the underlying connection pool
is closed on exit.
Read-only endpoints work without a token; a VNDB API token
<https://vndb.org/u/tokens>_ is only required for user-list writes and
authinfo.
Example
from vndb_client import Client with Client() as client: ... page = client.vn.query(filters=["id", "=", "v17"]) ... page.results[0].title 'Ever17 -the out of infinity-'
Attributes:
| Name | Type | Description |
|---|---|---|
vn |
QueryResource[VN]
|
Query resource for visual novels ( |
release |
QueryResource[Release]
|
Query resource for releases ( |
producer |
QueryResource[Producer]
|
Query resource for producers ( |
character |
QueryResource[Character]
|
Query resource for characters ( |
staff |
QueryResource[Staff]
|
Query resource for staff ( |
tag |
QueryResource[Tag]
|
Query resource for tags ( |
trait |
QueryResource[Trait]
|
Query resource for traits ( |
quote |
QueryResource[Quote]
|
Query resource for quotes ( |
ulist |
QueryResource[UlistEntry]
|
Query resource for user-list entries ( |
Create a synchronous client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | None
|
VNDB API token for authenticated requests. Omit for read-only access. |
None
|
base_url
|
str
|
API base URL. Defaults to production
( |
PROD_BASE_URL
|
timeout
|
float
|
Per-request timeout in seconds. |
DEFAULT_TIMEOUT
|
user_agent
|
str
|
|
DEFAULT_USER_AGENT
|
retry
|
RetryConfig | None
|
Retry policy for transient failures. |
None
|
http_client
|
Client | None
|
An existing |
None
|
cache_ttl
|
float | None
|
Time-to-live in seconds for the in-memory read cache.
|
None
|
cache_maxsize
|
int
|
Maximum number of cached read responses before
least-recently-used eviction. Only used when |
128
|
stats
¶
stats() -> Stats
Return database-wide totals from the /stats endpoint.
Returns:
| Type | Description |
|---|---|
Stats
|
The site-wide entity counts. |
authinfo
¶
authinfo() -> AuthInfo
Return identity and permissions for the current token (/authinfo).
Returns:
| Type | Description |
|---|---|
AuthInfo
|
The authenticated token's id, username, and granted permissions. |
get_user
¶
get_user(
q: str | list[str], *, fields: str | None = None
) -> dict[str, User | None]
Look up users by id or name via the /user endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
str | list[str]
|
A single user id/name, or a list of them. |
required |
fields
|
str | None
|
Optional comma-separated extra fields to request. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, User | None]
|
A mapping from each query term to its |
ulist_labels
¶
ulist_labels(
user: str | None = None, *, fields: str | None = None
) -> list[UlistLabel]
List the ulist labels for a user (/ulist_labels).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
str | None
|
The user id whose labels to fetch; defaults to the token's user. |
None
|
fields
|
str | None
|
Optional comma-separated extra fields to request. |
None
|
Returns:
| Type | Description |
|---|---|
list[UlistLabel]
|
The user's labels. |
schema
¶
schema() -> dict[str, Any]
Return the raw VNDB API schema document (/schema).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The schema as a plain JSON-decoded dict. |
set_ulist
¶
set_ulist(
vn_id: str,
*,
vote: int | None | UnsetType = UNSET,
notes: str | None | UnsetType = UNSET,
started: str | None | UnsetType = UNSET,
finished: str | None | UnsetType = UNSET,
labels: list[int] | None = None,
labels_set: list[int] | None = None,
labels_unset: list[int] | None = None,
) -> None
Create or update the authenticated user's ulist entry for a VN.
Each scalar argument defaults to UNSET (the field is omitted from the
request); pass None to clear it, or a value to set it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vn_id
|
str
|
The VN id (e.g. |
required |
vote
|
int | None | UnsetType
|
Vote in 10-100, |
UNSET
|
notes
|
str | None | UnsetType
|
Free-text notes, |
UNSET
|
started
|
str | None | UnsetType
|
Start date |
UNSET
|
finished
|
str | None | UnsetType
|
Finish date |
UNSET
|
labels
|
list[int] | None
|
Replace the entry's labels with this exact list of label ids. |
None
|
labels_set
|
list[int] | None
|
Label ids to add. |
None
|
labels_unset
|
list[int] | None
|
Label ids to remove. |
None
|
delete_ulist
¶
delete_ulist(vn_id: str) -> None
Remove the authenticated user's ulist entry for vn_id.
set_rlist
¶
set_rlist(release_id: str, *, status: int) -> None
Set the authenticated user's rlist status for a release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
release_id
|
str
|
The release id (e.g. |
required |
status
|
int
|
The rlist status; accepts an |
required |
delete_rlist
¶
delete_rlist(release_id: str) -> None
Remove the authenticated user's rlist entry for release_id.
AsyncClient
¶
AsyncClient(
token: str | None = None,
*,
base_url: str = PROD_BASE_URL,
timeout: float = DEFAULT_TIMEOUT,
user_agent: str = DEFAULT_USER_AGENT,
retry: RetryConfig | None = None,
http_client: AsyncClient | None = None,
cache_ttl: float | None = None,
cache_maxsize: int = 128,
)
Asynchronous VNDB Kana API client.
The async counterpart of :class:Client. It exposes the same entity query
resources and helpers, but query and the write/GET methods are
coroutines. Use it as an async context manager so the connection pool is
closed on exit.
Example
import asyncio from vndb_client import AsyncClient async def main() -> str: ... async with AsyncClient() as client: ... page = await client.vn.query(filters=["id", "=", "v17"]) ... return page.results[0].title asyncio.run(main()) 'Ever17 -the out of infinity-'
Attributes:
| Name | Type | Description |
|---|---|---|
vn |
AsyncQueryResource[VN]
|
Query resource for visual novels ( |
release |
AsyncQueryResource[Release]
|
Query resource for releases ( |
producer |
AsyncQueryResource[Producer]
|
Query resource for producers ( |
character |
AsyncQueryResource[Character]
|
Query resource for characters ( |
staff |
AsyncQueryResource[Staff]
|
Query resource for staff ( |
tag |
AsyncQueryResource[Tag]
|
Query resource for tags ( |
trait |
AsyncQueryResource[Trait]
|
Query resource for traits ( |
quote |
AsyncQueryResource[Quote]
|
Query resource for quotes ( |
ulist |
AsyncQueryResource[UlistEntry]
|
Query resource for user-list entries ( |
Create an asynchronous client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | None
|
VNDB API token for authenticated requests. Omit for read-only access. |
None
|
base_url
|
str
|
API base URL. Defaults to production
( |
PROD_BASE_URL
|
timeout
|
float
|
Per-request timeout in seconds. |
DEFAULT_TIMEOUT
|
user_agent
|
str
|
|
DEFAULT_USER_AGENT
|
retry
|
RetryConfig | None
|
Retry policy for transient failures. |
None
|
http_client
|
AsyncClient | None
|
An existing |
None
|
cache_ttl
|
float | None
|
Time-to-live in seconds for the in-memory read cache.
|
None
|
cache_maxsize
|
int
|
Maximum number of cached read responses before
least-recently-used eviction. Only used when |
128
|
stats
async
¶
stats() -> Stats
Return database-wide totals from the /stats endpoint.
Returns:
| Type | Description |
|---|---|
Stats
|
The site-wide entity counts. |
authinfo
async
¶
authinfo() -> AuthInfo
Return identity and permissions for the current token (/authinfo).
Returns:
| Type | Description |
|---|---|
AuthInfo
|
The authenticated token's id, username, and granted permissions. |
get_user
async
¶
get_user(
q: str | list[str], *, fields: str | None = None
) -> dict[str, User | None]
Look up users by id or name via the /user endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
str | list[str]
|
A single user id/name, or a list of them. |
required |
fields
|
str | None
|
Optional comma-separated extra fields to request. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, User | None]
|
A mapping from each query term to its |
ulist_labels
async
¶
ulist_labels(
user: str | None = None, *, fields: str | None = None
) -> list[UlistLabel]
List the ulist labels for a user (/ulist_labels).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
str | None
|
The user id whose labels to fetch; defaults to the token's user. |
None
|
fields
|
str | None
|
Optional comma-separated extra fields to request. |
None
|
Returns:
| Type | Description |
|---|---|
list[UlistLabel]
|
The user's labels. |
schema
async
¶
schema() -> dict[str, Any]
Return the raw VNDB API schema document (/schema).
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The schema as a plain JSON-decoded dict. |
set_ulist
async
¶
set_ulist(
vn_id: str,
*,
vote: int | None | UnsetType = UNSET,
notes: str | None | UnsetType = UNSET,
started: str | None | UnsetType = UNSET,
finished: str | None | UnsetType = UNSET,
labels: list[int] | None = None,
labels_set: list[int] | None = None,
labels_unset: list[int] | None = None,
) -> None
Create or update the authenticated user's ulist entry for a VN.
Each scalar argument defaults to UNSET (the field is omitted from the
request); pass None to clear it, or a value to set it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vn_id
|
str
|
The VN id (e.g. |
required |
vote
|
int | None | UnsetType
|
Vote in 10-100, |
UNSET
|
notes
|
str | None | UnsetType
|
Free-text notes, |
UNSET
|
started
|
str | None | UnsetType
|
Start date |
UNSET
|
finished
|
str | None | UnsetType
|
Finish date |
UNSET
|
labels
|
list[int] | None
|
Replace the entry's labels with this exact list of label ids. |
None
|
labels_set
|
list[int] | None
|
Label ids to add. |
None
|
labels_unset
|
list[int] | None
|
Label ids to remove. |
None
|
delete_ulist
async
¶
delete_ulist(vn_id: str) -> None
Remove the authenticated user's ulist entry for vn_id.
set_rlist
async
¶
set_rlist(release_id: str, *, status: int) -> None
Set the authenticated user's rlist status for a release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
release_id
|
str
|
The release id (e.g. |
required |
status
|
int
|
The rlist status; accepts an |
required |
delete_rlist
async
¶
delete_rlist(release_id: str) -> None
Remove the authenticated user's rlist entry for release_id.