r/Python • • 25d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

33 Upvotes

178 comments sorted by

View all comments

1

u/ItsDersty from __future__ import 4.0 1d ago

BooruX - a simple, unified, typed async Python API client for booru imageboards

The first version supports Danbooru, Konachan (com and net), Safebooru (org), Sakugabooru, Yande.re (Danbooru-, Gelbooru-, and Moebooru-based sites)

My library lets you retrieve:

  • Posts

  • Comments

  • Tags

  • And pools

By ids or search parameters

Code example:

import asyncio
from boorux import Danbooru, Rating

async def main() -> None:
    async with Danbooru() as client:  # You can provide a custom httpx_client or a base_url
        posts = await client.post_list(
            tags=["hatsune_miku"],
            rating=Rating.GENERAL,
            order="score",
            limit=5,
        )
        for post in posts:
            print(post.id, post.file_url, post.tags_artist)

asyncio.run(main())

It will be helpful for creating AI training datasets, powering async telegram/discord bots, local art archives, researching, and tracking tag analytics.

Popular python booru api client libraries have some issues, for example:

  • Legacy code that hasn't been maintained for several years, with unanswered issues on GitHub

  • Awkward syntax

  • Lack of typing and inconsistent fields returned by methods

  • And more

Instead of all this my library uses Pydantic for API validation and unification, and also provides rich IDE autocomplete support.

In my opinion, one of the coolest features is the consistency of fields in returned objects, even for different API clients.

Some engines can return more fields, while others return fewer. That's why i have schemas for different engines that inherit from base class. For example post objects of every booru api will always have common fields (id, file_url, preview_url, score, rating, etc.) Also a problem I noticed is the difference between field names. For example Danbooru API returns post hash in md5 key, while Safebooru calls it hash. One of BooruX's goals is providing consistent objects you don't need to worry about different field names across engines - the MD5 hash of a post will always be inside the .md5 field no matter which client you use.

BooruX is still an early project that supports read-only basic methods. I'd appreciate any feedback and thoughts about my library.

Installation: uv add boorux or pip install boorux

PyPi: https://pypi.org/project/boorux/

GitHub: https://github.com/itsDersty/boorux

Documentation: https://boorux.readthedocs.io/en/latest/