Skip to main content

PyPI version CI License: MIT Coverage Docs Code style: Ruff

A unified, async, type-safe Python client for Booru imageboards (Danbooru, Moebooru, Gelbooru), built with HTTPX and Pydantic v2.


Key Features

  • Unified & Engine-Specific Models: Consistent base schemas (Post, Comment, Tag, Pool) across all imageboards, extended with full engine-specific fields (DanbooruPost, MoebooruPost, GelbooruPost, DanbooruMediaAsset) validated via Pydantic v2.
  • Full IDE Autocomplete for Queries: Search methods use TypedDict + Unpack (PEP 692), giving you static type checking and IDE autocomplete for query filters, sorting literals, and date parameters.
  • Polymorphic Capability Protocols: Write generic, type-safe code against @runtime_checkable protocols (SupportsPosts, SupportsComments, SupportsTags, SupportsPools).
  • Clear Exception Hierarchy: All API errors map to structured BooruXError subclasses (NotFoundError, RateLimitError, CloudflareChallengeError, AuthenticationError, APIError).
  • HTTP/2 & Dependency Injection: Runs on httpx.AsyncClient with HTTP/2 enabled by default, or lets you inject your own configured AsyncClient for custom proxies, timeouts, headers, or mock transports.

Installation

Using pip:

pip install boorux

Or using uv:

uv add boorux

Quick Start

Basic Usage

Use any site client as an async context manager:

import asyncio
from boorux import Danbooru, Rating


async def main() -> None:
    async with Danbooru() as client:
        posts = await client.post_list(
            tags=["hakurei_reimu", "solo"],
            rating=Rating.GENERAL,
            limit=5,
        )
        for post in posts:
            print(
                f"#{post.id} [{post.rating}] {post.width}x{post.height} -> {post.file_url}"
            )


asyncio.run(main())

Engine-Specific Features

Each client returns models tailored to its underlying platform while keeping common fields consistent:

import asyncio
from boorux import Danbooru, Konachan


async def main() -> None:
    async with Danbooru() as danbooru:
        # Categorized tag lists, media variants, and cursor pagination
        posts = await danbooru.post_list(tags=["forest"], before_id=12_400_000, limit=5)
        if posts:
            print("Artists:", posts[0].tags_artist)
            print("Characters:", posts[0].tags_character)

    async with Konachan() as konachan:
        pool = await konachan.pool_get(17)
        print(f"Pool '{pool.name}': {len(pool.posts)} posts, IDs: {pool.post_ids[:5]}")


asyncio.run(main())

Polymorphic Code with Protocols

Write functions that work across any compatible imageboard, or check optional features at runtime:

import asyncio
from boorux import Danbooru, Safebooru, SupportsPools, SupportsPosts


async def inspect_board(client: SupportsPosts, tag: str) -> None:
    posts = await client.post_list(tags=[tag], limit=1)
    if posts:
        post = posts[0]
        print(f"Found #{post.id} ({post.width}x{post.height}): {post.file_url}")

    if isinstance(client, SupportsPools):
        pools = await client.pool_list(limit=1)
        print("Supports pools! Latest:", pools[0].name if pools else "none")
    else:
        print("This board does not support pools.")


async def main() -> None:
    async with Danbooru() as danbooru, Safebooru() as safebooru:
        await inspect_board(danbooru, "forest")
        await inspect_board(safebooru, "forest")


asyncio.run(main())

Custom httpx.AsyncClient & Mirrors

Pass an external httpx.AsyncClient to configure proxies, timeouts, custom User-Agent headers (recommended by Danbooru for bots), or alternative transports. When an external client is provided, BooruX will not close it on context exit:

import asyncio
import httpx
from boorux import Danbooru, Konachan


async def main() -> None:
    custom_http = httpx.AsyncClient(
        http2=True,
        headers={"User-Agent": "MyBot/1.0 (user #12345)"},
        timeout=httpx.Timeout(30.0),
    )

    async with Danbooru(httpx_client=custom_http) as client:
        post = await client.post_get(12370421)
        print(post.file_url)

    await custom_http.aclose()

    # Override base_url to use mirrors (e.g., Konachan's SFW mirror)
    async with Konachan(base_url="https://konachan.net") as sfw_konachan:
        posts = await sfw_konachan.post_list(tags=["forest"], limit=5)
        print(f"Fetched {len(posts)} posts from mirror")


asyncio.run(main())

Supported Sites & Capabilities

Site Default URL Engine Posts Comments Tags Pools
Danbooru danbooru.donmai.us DanbooruEngine ✅ ✅ ✅ ✅
Konachan konachan.com MoebooruEngine ✅ ✅ ✅ ✅
Yandere yande.re MoebooruEngine ✅ ✅ ✅ ✅
Sakugabooru www.sakugabooru.com MoebooruEngine ✅ ✅ ✅ ✅
Safebooru safebooru.org GelbooruEngine ✅ ⚠️ List only ✅ ❌

Note:

  • Safebooru: Supports comment_list, but does not provide a comment_get endpoint or a pools API (pool_list / pool_get).
  • Danbooru Limits: Unauthenticated users are limited to searching 2 tags per query (registered accounts get 3). System metatags such as rating:, score, id, and md5: are exempt from this limit. Maximum page size is 200 for posts and 1000 for other endpoints.

Error Handling

API-level errors raise subclasses of BooruXError:

import asyncio
import httpx
from boorux import (
    APIError,
    AuthenticationError,
    BooruXError,
    CloudflareChallengeError,
    Danbooru,
    NotFoundError,
    RateLimitError,
)


async def main() -> None:
    async with Danbooru() as client:
        try:
            post = await client.post_get(999_999_999)
        except NotFoundError:
            print("Resource does not exist.")
        except RateLimitError as exc:
            print(f"Rate limited ({exc.status_code}) at {exc.url}")
        except CloudflareChallengeError as exc:
            print(f"Blocked by Cloudflare challenge at {exc.url}")
        except AuthenticationError as exc:
            print(f"Access denied ({exc.status_code}) at {exc.url}")
        except APIError as exc:
            print(f"API error ({exc.status_code}) at {exc.url}")
        except BooruXError as exc:
            print(f"BooruX error: {exc}")
        except httpx.RequestError as exc:
            print(f"Network or timeout error: {exc}")


asyncio.run(main())

Note: Low-level transport errors (httpx.RequestError, timeouts) and schema validation errors (pydantic.ValidationError) are propagated directly from httpx and pydantic rather than being masked.


Roadmap

Planned additions for future releases:

  • Authentication & Write Endpoints: API key and hash authentication, creating comments, voting, and uploading posts.
  • More Sites: Wider booru sites support.
  • Built-in Tools (boorux.tools): Streaming media downloader, concurrent batch downloads, and async auto-pagination iterators.

License

This project is licensed under the MIT License.

Metadata

Release files for boorux 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for boorux 0.1.0
File Size Uploaded Provenance Actions
boorux-0.1.0.tar.gz 20.8 kB Without provenance Details for boorux-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for boorux 0.1.0
File Interpreter ABI Platform Actions
boorux-0.1.0-py3-none-any.whl Python 3 none any Details for boorux-0.1.0-py3-none-any.whl

Total release size: 50.4 kB

Release files / boorux-0.1.0.tar.gz

Download URL boorux-0.1.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dcd601945dee597a116915ee9d169809a9356a0df3ef5732dd3c0b0e29976824
BLAKE2b-256 checksum
How to use checksums
241b4e53d96d1c801e6f3341d982b5a2975f4e50a07904d5d16bc7f9560059f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / boorux-0.1.0-py3-none-any.whl

Download URL boorux-0.1.0-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ee7ca9455103702f0cefe51934ffc76be1bff8f6dbb90f1c0fec46a61b417a0
BLAKE2b-256 checksum
How to use checksums
a69d79f09021f33db023c570598885a474b7400c079fe6c948e2bf6172cc38b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for boorux 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page