A simple Python wrapper for the waifu.pics API.
Python 3.6 or higher is required.
Install from PyPI
$ pip install waifu-py
Install from source
$ pip install git+https://github.com/IchBinLeoon/waifu-py
You can use either WaifuClient or WaifuAioClient, depending on whether you want a synchronous wrapper class, or an asynchronous wrapper class. Below are some examples of how to use WaifuClient and WaifuAioClient.
from waifu import WaifuClient
client = WaifuClient()
# Get one SFW image
sfw_waifu: str = client.sfw(category='waifu')
# Get 30 unique SFW images
sfw_megumin_list: list = client.sfw(category='megumin', many=True)
# Get 30 unique SFW images and exclude images in list
sfw_megumin_list_exclude: list = client.sfw(category='megumin', many=True, exclude=['https://i.waifu.pics/IqD8csE.png', 'https://i.waifu.pics/NV-dfTH.png'])
# Get one NSFW image
nsfw_neko: str = client.nsfw(category='neko')
# Get 30 unique NSFW images
nsfw_trap_list: list = client.nsfw(category='trap', many=True)
import asyncio
from waifu import WaifuAioClient
async def main():
async with WaifuAioClient() as client:
# Get one SFW image
sfw_neko: str = await client.sfw(category='neko')
# Get 30 unique SFW images
sfw_shinobu_list: list = await client.sfw(category='shinobu', many=True)
# Get one NSFW image
nsfw_waifu: str = await client.nsfw(category='waifu')
# Get 30 unique NSFW images
nsfw_neko_list: list = await client.nsfw(category='neko', many=True)
asyncio.run(main())
import asyncio
from waifu import WaifuAioClient
async def main():
client = WaifuAioClient()
# Get one SFW image
sfw_waifu: str = await client.sfw(category='waifu')
# Get 30 unique NSFW images
nsfw_waifu_list: list = await client.nsfw(category='waifu', many=True)
await client.close()
asyncio.run(main())
If you want to use your own requests or aiohttp session, you can do that too.
import requests
from waifu import WaifuClient
session = requests.Session()
client = WaifuClient(session=session)
# ...
import asyncio
import aiohttp
from waifu import WaifuAioClient
async def main():
session = aiohttp.ClientSession()
async with WaifuAioClient(session=session) as client:
# ...
asyncio.run(main())
import asyncio
import aiohttp
from waifu import WaifuAioClient
async def main():
session = aiohttp.ClientSession()
client = WaifuAioClient(session=session)
# ...
await client.close()
asyncio.run(main())
You can also view all valid image categories.
from waifu import ImageCategories
print(ImageCategories)
Output:
{
"sfw":[
"waifu",
"neko",
"shinobu",
"megumin",
"bully",
"cuddle",
"cry",
"hug",
"awoo",
"kiss",
"lick",
"pat",
"smug",
"bonk",
"yeet",
"blush",
"smile",
"wave",
"highfive",
"handhold",
"nom",
"bite",
"glomp",
"slap".
"kill",
"kick",
"happy",
"wink",
"poke",
"dance",
"cringe"
],
"nsfw":[
"waifu",
"neko",
"trap",
"blowjob"
]
}
Contributions are welcome! Feel free to open issues or submit pull requests!
MIT © IchBinLeoon