A simple Python wrapper for the Konachan.net API, allowing you to easily browse and download images.
- Object-Oriented: Image data is wrapped in an
Imageclass for easy access to metadata (tags, URLs, dimensions, etc.). - Flexible Fetching: Retrieve images by page, fetch random images, or get a single image.
- Easy Saving: Built-in functions to download and save images locally.
- JSON Serializable: Easy conversion back to raw dictionary format.
Ensure you have the requests library installed:
pip install requestsfrom KonachanAPI import get_images, save_image
# Fetch the first image from page 1
images = get_images(limit=1, page=1)
# Save the first image to the 'images' folder
if images:
save_image(images[0])from KonachanAPI import get_images_random, save_images
# Fetch 10 random images
random_images = get_images_random(limit=10)
# Save all fetched images
save_images(random_images)Each Image object contains all the fields returned by the Konachan API:
image = images[0]
print(f"ID: {image.id}")
print(f"Tags: {image.tags}")
print(f"File URL: {image.file_url}")
print(f"Original Dict: {image.json}")KonachanAPI.py: The core library containing theImageclass and API functions.main.py: Example scripts demonstrating how to use the library.images/: Default directory for saved images.images.json: Sample output file for serialized image metadata.