Skip to main content

A Python wrapper for waifu.im API.

Project description

waifuim.py

PyPI - Python Version PyPI License

A Python wrapper for waifu.im API.

Table of Contents

Installation

Python 3.6 or higher is required.

Install from PyPI

$ pip install waifuim.py

Install from source

$ pip install git+https://github.com/Waifu-im/waifuim.py

Usage

For now, you can only use WaifuAioClient which is async. Maybe a sync client will be released in the future. Most of the methods returns an Image instance, the attributes are the same from the ones returned by the API.

Examples with WaifuAioClient

import asyncio

from waifuim import WaifuAioClient

async def main():

    wf = WaifuAioClient()
    
    # Get a completely random image
    image = await wf.search()
    
    # Get an image by tags
    image = await wf.search(included_tags=['waifu','maid'],excluded_tags=['ero'])
    
    # Get sfw waifu images ordered by FAVOURITES
    images = await wf.search(included_tags=['waifu'],is_nsfw='null',many=True,order_by='FAVOURITES')
    
    # Get a user favourites
    favs = await wf.fav(token='The user token if no token is provided it use the one in the client constructor')
    
    # Edit your favourites
    await wf.fav_delete(3133)
    await wf.fav_insert(3133,user_id=11243585148445,token='user_id and token are optional')
    fav_state = await wf.fav_toggle(4401)
    # fav_state wil be equal to 'INSERTED' or 'DELETED'
 
    await wf.close()
    
    # You can also use a context manager but for multiple request it is not recommended
    
    async with WaifuAioClient() as wf:
        # Do your stuff

asyncio.run(main())

The Image and Tag instance

In most of the case the methods will return an Image instance. The attributes are the same as the json keys that the api returns.

image = await wf.search()
>>> <waifuim.types.Image object at 0x76217ccf10>

image.url
>>> 'https://cdn.waifu.im/1982.jpg'

str(image)
>>> 'https://cdn.waifu.im/1982.jpg'

image.signature
>>> aa48cd9dc6b64367

image.tags[0]
>>> <waifuim.types.Tag object at 0x73214ccf10>

Some useful kwargs in the constructor

from waifuim import WaifuAioClient

wf = WaifuAioClient(
    session=an_aiohttpClientSession_created_asynchronously,
    appname="TheNameOfYourApplication",
    token="The default token to use in routes requiring authentication.",
)

# ...

License

MIT © Buco

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

waifuim.py-3.2.9.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file waifuim.py-3.2.9.tar.gz.

File metadata

  • Download URL: waifuim.py-3.2.9.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for waifuim.py-3.2.9.tar.gz
Algorithm Hash digest
SHA256 b779e9615ce768093d0c1cf29a789398fb6aa669f48cbcff6d6079f29b873320
MD5 7081421612772050048778563109aab5
BLAKE2b-256 6c8fc79e48923b7a0897a94039c49a6938aebdb80f137c2eb1617b64d08506ed

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