Skip to main content

PyGelbooru is an unofficial and lightweight asynchronous library for Gelbooru compatible API's.

Project description

PyGelbooru

GitHub

PyGelbooru is an unofficial and lightweight asynchronous library for the Gelbooru API.

Installation

This library requires Python 3.6 or above.

You can install the library through pip as follows,

pip install pygelbooru

Usage

Searching

The primary use for this library is, naturally, to search for images with specific tags.

This can be done as so:

from pygelbooru import Gelbooru

# API key/user ID is optional, but access may be limited without them
gelbooru = Gelbooru('API_KEY', 'USER_ID')

results = await gelbooru.search_posts(tags=['dog ears', '1girl'], exclude_tags=['nude'])
[<GelbooruImage(id=5105386, filename='b77e69be0a4b...dde071dc.jpeg', owner='anon2003')>,
 <GelbooruImage(id=5105161, filename='bf169f891ebe...02bceb5e.jpeg', owner='cpee')>,
 <GelbooruImage(id=5104148, filename='46df3ebe2d41...4316d218e.jpg', owner='danbooru')>,
 <GelbooruImage(id=5104080, filename='e8eec23d151e...419293401.png', owner='anon2003')>,
 <GelbooruImage(id=5103937, filename='5bf279f3c546...be3fc53c8.jpg', owner='danbooru')>,
 ...

Tags can contain spaces when passed as arguments, they will simply be reformated with underscores before being queried, so you don't need to reformat them yourself.

Results are returned as a list of GelbooruImage containers. When cast to a string, this will return the image_url,

str(results[0])
'https://img2.gelbooru.com/images/b7/7e/b77e69be0a4b581eac597527dde071dc.jpeg'

You can also pull other information returned by the API, https://github.com/FujiMakoto/pygelbooru/blob/master/pygelbooru/gelbooru.py#L32-L47

Searching (Random)

In addition to searching for a large list of images, PyGelbooru also provides a helper method for when you're really just after a single, random image that matches the specified tags.

This method will automatically pull a random image from the last 20,000 Gelbooru image submissions.

result = await gelbooru.random_post(tags=['cat ears', '1girl', 'cat hood', 'bell'], exclude_tags=['nude'])
<GelbooruImage(id=5106718, filename='bbbdfbf9e883...161753514.png', owner='6498')>

Comments

You can fetch post comments directly from the GelbooruImage container,

post = await gelbooru.get_post(5099841)
await post.get_comments()
[<GelbooruComment(id=2486074, author='Anonymous', created_at='2020-01-28 08:47')>]

Tags

Besides searching for images, you can also pull information on tags as follows,

await gelbooru.tag_list(name='dog ears')
<GelbooruTag(id=773, name='dog_ears', count=22578)>

# Use "name_pattern" to search for partial matches to a specified tag
await gelbooru.tag_list(name_pattern='%splatoon%', limit=4)
[<GelbooruTag(id=892683, name='splatoon_(series)', count=11353)>,
 <GelbooruTag(id=759189, name='splatoon_2', count=3488)>,
 <GelbooruTag(id=612372, name='aori_(splatoon)', count=2266)>,
 <GelbooruTag(id=612374, name='hotaru_(splatoon)', count=2248)>]

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

pygelbooru-0.5.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

pygelbooru-0.5.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file pygelbooru-0.5.0.tar.gz.

File metadata

  • Download URL: pygelbooru-0.5.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for pygelbooru-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c3a7d702384744c0ea4bbcf8cd9c5d22060c21e2124bb0c43650a84a7715176e
MD5 a56cf93182a26927c60527ef8a221ffe
BLAKE2b-256 3ec4e3291d3e7985d9269c02832fcc9863682ca4456c187d033a5597761fb8f2

See more details on using hashes here.

File details

Details for the file pygelbooru-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pygelbooru-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for pygelbooru-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f709c0abd3f6a02af85a401b2d9b559ce6e0f490cf4faeed37f1227cad6bc6e
MD5 72637ee150ed975ee9b1eb9b29eabb76
BLAKE2b-256 91fbb85a9410429f568a4c473c7590cc05c3fab037b25d9197d0f6c995042cfd

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