Skip to main content

A simple async Python wrapper for nekos.best API.

Project description

nekos-best.py

PyPI

A simple async Python wrapper for nekos.best API.

Join the official Discord server here.

Requirements

  • aiohttp (>=3.6.2)

Installation

Make sure to have pip installed in your environement. It will also install all requirements.

pip install -U nekosbest

Example

import asyncio

from nekosbest import Client


async def main() -> None:
    client = Client()
    try:
        single = await client.get_image("neko")
        print(single)
        multiple = await client.get_image("neko", 3)
        print(multiple)
    finally:
        await client.close()


asyncio.run(main())

Recommended usage

Use Client as an async context manager so the underlying HTTP session is always closed cleanly, even if an error is raised:

import asyncio

from nekosbest import Client


async def main() -> None:
    async with Client() as client:
        result = await client.get_image("neko")
        print(result.url)
        if result.dimensions is not None:
            print(result.dimensions.width, result.dimensions.height)


asyncio.run(main())

Exception handling

All exceptions raised by the library inherit from NekosBestBaseError. The most common ones you may want to catch:

  • NotFound — the requested category did not exist on the API.
  • APIError — the API returned an unexpected non-2xx status. The status code is available on err.code.
  • ClientError — the HTTP client could not reach the API (DNS failure, timeout, connection reset, ...). The underlying aiohttp.ClientConnectionError is preserved on err.__cause__.
from nekosbest import APIError, Client, ClientError, NotFound


async def fetch(client: Client, category: str) -> None:
    try:
        result = await client.get_image(category)
    except NotFound:
        print(f"unknown category: {category}")
    except APIError as err:
        print(f"nekos.best returned {err.code}")
    except ClientError as err:
        print(f"could not reach nekos.best: {err.__cause__}")
    else:
        print(result.url)

Changelog

See CHANGELOG.md for the full release history, including migration notes for every breaking change.

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

nekosbest-1.2.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

nekosbest-1.2.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file nekosbest-1.2.0.tar.gz.

File metadata

  • Download URL: nekosbest-1.2.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for nekosbest-1.2.0.tar.gz
Algorithm Hash digest
SHA256 066f4cb7894d3cb987c6b3e5e84261ce6e4dcf94bb95027b15eade4706b4e3f2
MD5 5d3b05d340a0ccda95bf44f822fe9394
BLAKE2b-256 8ec8274b21d767e8e8e27f6fb67626e7792ae08f13b9b783cfa5328b5a162119

See more details on using hashes here.

File details

Details for the file nekosbest-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: nekosbest-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for nekosbest-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29e701a62464b39c91540ba1bd34f86216388846467e6d53893dfbc878b2d252
MD5 6c56e1bcbdfdae74974584543c7aa657
BLAKE2b-256 2bd88864c1b919e7b7549821d8eba3c54766e5606c042a975b1fd9b25e44b49e

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