PyNekos

Python client for the https://nekos.moe/ API


Keywords
Nekos, moe, Neko, API
License
MIT
Install
pip install PyNekos==1.41

Documentation

PyNekos: a Python client for the Nekos.moe API

PyNekos provides a simple and pythonic way to use the Nekos.moe API.

The full documentation for PyNekos can be found here.

Setup

Some functionalities of the API needs authentication, used for post images and regenerate and get token. This way, if you pretend to use this functionalities, you'll need to sign up for a (free) account that authorizes access to the Nekos.moe API. If you pretend to use only the simple functionalities (like get images informations, user informations, search for images, etc), you don't even need to instance an object of the Neko class, see usage section below.

Installation

PyNekos requires Python 3.

Use pip to install the package from PyPI:

pip install PyNekos

Usage

Import the package:

from PyNekos.nekosapi import Neko

If you pretend to use more advanced functionalities of the API, you'll need the token. To get the token, you'll need your credentials:

from PyNekos.nekosapi import Neko
nyan = Neko(username='myuser', password='iwillnotshowyouthis')
token = nyan.get_token()
print(token)

After that, instance the object again with the token:

from PyNekos.nekosapi import Neko
nyan = Neko(token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

If you're gonna use only the simple functionalities (those that don't need authentication) you don't even need to instance a object of the Neko class, only need to call directly the method needed. See examples section below.

Examples

Getting a random image:

from PyNekos.nekosapi import Neko
random_json = Neko.random_image()
print(random_json)

Getting the link of the image ID and downloading the image:

from PyNekos.nekosapi import Neko
image_down = Neko.get_link('Sy9sHFa8X', down=True)
print(image_down)

You can see the usage of all endpoints of the API in the example files.

Changelog

  • Version 1.4:

Implemented @classmethod on methods to prevent unnecessary instances with simple functionalities

Fixed logic problems

Implemented new exceptions and refactored some old for semantic improvement

Methods "get_link" and "get_thumbnail" now have option to downloads the image of the url of the given image ID

  • Version 1.3:

Implemented **kwargs in some methods for packing and unpacking

Fixed some logic problems

Implemented better exceptions

Method "random_images" now have url of the image and url of the thumbnail in all entries of the json (before only had on the first entrie)

Contributing

Please contribute! If you want to fix a bug, suggest improvements, or add new features to the project, just open an issue or send a pull request.