No description
  • Rust 95.2%
  • Python 4.7%
  • Shell 0.1%
Find a file
2024-09-06 10:02:31 -07:00
.github/workflows ci(ci_yaml): splitting ci.yaml into ci.yaml and cd.yaml to speed up build 2024-09-06 09:51:02 -07:00
docs docs(pydocs): full python wrapper documentation 2024-09-05 14:33:45 -07:00
szurubooru-client bump: version 0.6.0 → 0.6.1 2024-09-06 10:02:31 -07:00
tests test(test_py): adding named token typesafe test 2024-09-06 10:01:40 -07:00
.cz.toml ci(cz): adding commitizen config 2024-08-10 18:04:07 -07:00
.gitignore docs(gitignore): ignoring python docs build artifacts 2024-09-05 11:33:41 -07:00
.pre-commit-config.yaml fix(models): fixing parsing of snapshot data 2024-08-11 13:36:39 -07:00
Cargo.lock docs(changelog): updating changelog for 0.6 2024-09-05 21:45:28 -07:00
Cargo.toml test(szurubooru-integration-test): removing old integration test, relocated to /tests directory 2024-08-21 07:32:42 -07:00
CHANGELOG.md docs(changelog): updating changelog for 0.6 2024-09-05 21:45:28 -07:00
cliff.toml docs: Adding changelog 2024-08-10 00:42:58 -07:00
LICENSE docs(license): adding MIT license 2024-09-05 15:31:54 -07:00
README.md docs(readme): updating readme with Python examples 2024-09-06 10:02:14 -07:00

szurubooru-client

SzurubooruClient is a wrapper around the excellently-documented Szurubooru API, including type-safe (if not API-safe) Query and Sort tokens. Includes a Python wrapper.

From Rust

Creating a new client

Basic authentication

Please keep in mind that this is not the preferred method of authentication. Tokens are far superior.

use szurubooru_client::SzurubooruClient;
let client = SzurubooruClient::new_with_basic_auth("http://localhost:5001", "myuser",
    "mypassword", true).unwrap();

Token authentication

The far superior and more secure means of authentication

use szurubooru_client::SzurubooruClient;
let client = SzurubooruClient::new_with_token("http://localhost:5001", "myuser", "sz-123456", true).unwrap();

For all other methods for making the requests, see the documentation.

From Python

Install the client using pip install szurubooru-client

from szurubooru_client import *
from szurubooru_client.tokens import *
from szurubooru_client.models import *

Creating a client

client = SzurubooruSyncClient("http://localhost:9802", username="integration_user",
                                       password="integration_password", allow_insecure=True)

Creating a new tag

foo_tag = client.create_tag("foo", category="default", description="The foo tag")
assert foo_tag.names == ["foo"]

Returning only a subset of fields

# Omit the "description" field
tags = client.list_tags(fields=["version", "names", "category"])
assert tags.results[0].description is None

Uploading from a file path

folly1 = client.create_post(file_path="../folly1.jpg",
                            tags=["maine_coon", "cat", "folly1"],
                            safety=PostSafety.Safe)

Searching for an existing post using an image

folly1_search = client.post_for_image("../folly1.jpg")
assert folly1_search is not None

Querying by an anonymous tag

cat_posts = client.list_posts(query=[anonymous_token("cat")])

Querying by a named tag

mc_posts = client.list_posts(query=[named_token(PostNamedToken.Tag, "maine_coon")])

Pagination

posts = client.list_posts(limit=1)
assert posts.total == 4
assert len(posts.results) == 1

posts2 = client.list_posts(limit=1, offset=1)
assert posts.results != posts2.results

Commenting on a post

cat_results = client.list_posts([anonymous_token("cat")])
post_id = cat_results.results[0].id

comment = client.create_comment("Excellent cat!", post_id)

Getting all comments for a post

comment_list = client.list_comments([named_token(CommentNamedToken.Post, post_id)])
assert len(comment_list.results) != 0

Downloading an image to a local path

cat_results = client.list_posts([anonymous_token("cat")])
post_id = cat_results.results[0].id

client.download_image_to_path(post_id, "/tmp/cat.jpg")