Skip to content

UndefinedClear/KonachanAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KonachanAPI

A simple Python wrapper for the Konachan.net API, allowing you to easily browse and download images.

Features

  • Object-Oriented: Image data is wrapped in an Image class 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.

Installation

Ensure you have the requests library installed:

pip install requests

Usage

Basic Example

from 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])

Fetching Random Images

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)

Accessing Metadata

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}")

Project Structure

  • KonachanAPI.py: The core library containing the Image class 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages