Skip to main content

Python interface for szurubooru

Project description

pyszuru

Python interface for szurubooru

Installation: pip install pyszuru

Usage

Creating API Instance

import pyszuru
mybooru = pyszuru.API(
    "https://example.com/booru",
    username="alice",
    # Authenticate with a password
    password="hunter2",
    # Or use a token
    token="my-token-string",
    # Optionally specify a API base URL if it differs from the default configuration
    # api_url="/booru-api", <-- relative to base URL
    # api_url="https://api.example.com/booru", <-- new absolute base
)

Working with tags

Note: it is reccomended to use the factory functions outlined below instead of calling the Tag constructor directly.

Get existing tag

Get an existing tag from the booru by referencing it by name

marvel_comics_tag = mybooru.getTag("marvel_comics")

Create new tag

Create a new tag, must specifiy a primary name only

spiderman_tag = mybooru.createTag("spiderman")

Alter properties of tag

spiderman_tag.implications = spiderman_tag.implications + [marvel_comics_tag]
spiderman_tag.push()

Working with posts

Note: it is reccomended to use the factory functions outlined below instead of calling the Post constructor directly.

Get existing post

my_old_post = mybooru.getPost(1337)

Create a post

with open("image.jpg", "rb") as f:
    file_token = mybooru.upload_file(f)
my_new_post = mybooru.createPost(file_token, "safe")

Alter tags of a post

my_new_post.tags = [marvel_comics_tag, spiderman_tag]
my_new_post.push()

Searching

Searching across tags

unused_tags = mybooru.search_tag("usages:0")

Searching across posts

for post in mybooru.search_post(
    "marvel_comics type:image special:fav", show_progress_bar=True
):
    wget.download(post.content)

Reverse image search

with open("similar.jpg", "rb") as f:
    similar_file_token = mybooru.upload_file(f)
result = mybooru.search_by_image(similar_file_token)
if result:
    if any(x.exact for x in result):
        raise Exception("Found an exact match")
    else:
        warnings.warn(f"Found {len(result)} similar posts")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyszuru-0.3.1.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

pyszuru-0.3.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file pyszuru-0.3.1.tar.gz.

File metadata

  • Download URL: pyszuru-0.3.1.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pyszuru-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ae381479cde1f932fe20a40a7a47be4cfd6841fdbb26eae7a826ff1b8f19c61d
MD5 6cf014fad3d3b8a68e430e0ac4b4e900
BLAKE2b-256 4073a4f7c398f5b6d290b58713021f29a269ea33653e38fb6ad0bfece94be517

See more details on using hashes here.

File details

Details for the file pyszuru-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pyszuru-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pyszuru-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d7e3bc2123280d5937e8b281e1a3d29d4d1bba75ffb23b9b6e7f7abfd0df9f2
MD5 d3eaf2d151d5fadeae0905c5b5dc142e
BLAKE2b-256 196acfa75cce31809bc8c7e6bb63fe425421288fb49202d8934f27675ae49418

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page