API Reference

The following section outlines the API of weeb.sh.

Note

This module uses the Python logging module to log diagnostic and errors in an output independent way. If the logging module is not configured, these logs will not be output anywhere.

Weeb.sh Client

class weebapi.client.Client(api_key: str, wolke_token: bool = True, v2_api: bool = False, base_url: str = 'https://api.weeb.sh/', bot=None, loop=<_UnixSelectorEventLoop running=False closed=False debug=False>)[source]

Client object for Weeb.sh V2

This is a client object for Weeb.sh API. Here are two versions. Basic without discord.py bot and a pluggable version that inserts this client object directly into your discord.py bot.

Represents a client connection that connects to weeb.sh. It works in two modes:
  1. As a standalone variable.

  2. Plugged-in to discord.py Bot or AutoShardedBot, see Client.pluggable

Parameters
  • api_key (str) – Your weeb.sh api token.

  • wolke_token (bool[Optional]) – Not required. Is the api token type Wolke or Bearer. Default: True

  • v2_api (bool[Optional]) – Not required. Use v2 API. Default: False

  • **base_url (str[Optional]) – Not required. Specify different DBL API url.

  • **base_urlNot required. Specify different base url.

  • **bot (Bot or AutoShardedBot) – Your bot client from discord.py

  • **loop (asyncio loop) – Your asyncio loop.

classmethod pluggable(bot, api_key: str, *args, **kwargs)[source]

Pluggable version of Client. Inserts Client directly into your Bot client. Called by using bot.dbl

Parameters

Note

Takes the same parameters as Client class. Usage changes to bot.weebsh. (bot is your bot client variable)

get_image(image: str) → weebapi.data_objects.Image[source]

This function is a coroutine.

This function gets image by it’s ID.

Parameters

image (str or weebapi.data_objects.Image) – Image ID from string or weebapi.data_objects.Image object.

Returns

weebapi.data_objects.Image

get_preview(type_name: str, hidden: bool = False, nsfw: int = 1) → weebapi.data_objects.Preview[source]

This function is a coroutine.

This function gets a preview of the specified image type.

1 (Default)

If the value of the nsfw parameter is 1, content with nsfw will be hidden.

2

If the value of the nsfw parameter is 2, both nsfw and non-nsfw content will be shown.

3

If the vaule of the nsfw parameter is 3, only content marked with nsfw will be shown.

Parameters
  • type_name (str) – Name of the image type for which you want the preview.

  • **hidden (bool) – Search in hidden image types. Defaults to False.

  • **nsfw (int) – Display options for NSFW content. Look for the valid values in the box above.

Returns

weebapi.data_objects.Preview

get_random(tags: str = None, image_type: str = None, nsfw: int = 1, hidden: bool = False, file_type: str = None) → weebapi.data_objects.Image[source]

This function is a coroutine.

This function gets a random image of the specified tags or the image type.

Note

Make sure you either use comma separated or list of tags and/or one image type. You cannot leave both tags nor image_type variable blank, one of them must be used.

1 (Default)

If the value of the nsfw parameter is 1, content with nsfw will be hidden.

2

If the value of the nsfw parameter is 2, both nsfw and non-nsfw content will be shown.

3

If the vaule of the nsfw parameter is 3, only content marked with nsfw will be shown.

Parameters
  • **tags (str or list) – One tag or comma separated tags or list of image tags.

  • **image_type (str) – Specify image type.

  • **hidden (bool) – Get hidden image tags. Defaults to False.

  • **nsfw (int) – Display options for NSFW content. Look for the valid values in the box above.

  • **file_type (str) – One of jpg, jpeg, png, gif file types.

Returns

Returns the weebapi.data_objects.Image object.

get_tags(hidden: bool = False, nsfw: int = 1) → list[source]

This function is a coroutine.

This function gets the list of all available image tags.

1 (Default)

If the value of the nsfw parameter is 1, content with nsfw will be hidden.

2

If the value of the nsfw parameter is 2, both nsfw and non-nsfw content will be shown.

3

If the vaule of the nsfw parameter is 3, only content marked with nsfw will be shown.

Parameters
  • **hidden (bool) – Get hidden image tags. Defaults to False.

  • **nsfw (int) – Display options for NSFW content. Look for the valid values in the box above.

Returns

Returns the list of weebapi.data_objects.Tag objects.

get_types(hidden: bool = False, nsfw: int = 1) → list[source]

This function is a coroutine.

This function gets the list of all available image types.

1 (Default)

If the value of the nsfw parameter is 1, content with nsfw will be hidden.

2

If the value of the nsfw parameter is 2, both nsfw and non-nsfw content will be shown.

3

If the vaule of the nsfw parameter is 3, only content marked with nsfw will be shown.

Parameters
  • **hidden (bool) – Get hidden image types. Defaults to False.

  • **nsfw (int) – Display options for NSFW content. Look for the valid values in the box above.

Returns

Returns the list of weebapi.data_objects.ImageType objects.

Data objects

Here is the collection of all data objects that this API wrapper uses.

Image

class weebapi.data_objects.Image(snowflake: str, image_type: str, base_type: str, nsfw: bool, file_type: str, mime_type: str, tags: list, url: str, hidden: bool, account: str, client, source: str = '')[source]

Represents an image from Weeb.sh.

snowflake

str – The image ID.

image_type

ImageType – Type of the image.

base_type

str – Base type of the image.

nsfw

bool – Is image NSFW (not safe for work).

file_type

str – Image file type.

mime_type

str – Image MIME type.

hidden

bool – Is image private.

account

str – ID of the poster.

source

Optional[str] – Source of the image.

tags

list – List of Tag objects.

url

str – CDN URL of the image.

add_tags(tags: list)[source]

This function is a coroutine.

Adds tags to this image.

Parameters

tags (list) – List of strings.

Raises

Forbidden: – If required permissions are absent.

delete()[source]

This function is a coroutine.

Removes current image.

Raises

Forbidden: – If required permissions are absent.

remove_tags(tags: list)[source]

This function is a coroutine.

Removes tags from this image.

Parameters

tags (list) – List of strings.

Raises

Forbidden: – If required permissions are absent.

Preview

class weebapi.data_objects.Preview(snowflake: str, url: str, file_type: str, base_type: str, image_type: str, client)[source]

This class represents a preview object.

str()

By itself it returns the image URL.

snowflake

str – Unique image identifier.

url

str – URL of the preview image.

image_type

ImageTypeImageType object.

base_type

str – Image base type.

file_type

str – Image file type.

ImageType

class weebapi.data_objects.ImageType(name: str, client)[source]

This object represents an image type. By itself returns the name.

str()

Returns the name of the image type.

name

str – Name of the image type.

get_preview

This function is a coroutine.

Returns a Preview object of the image type.

Returns

Preview

Tag

class weebapi.data_objects.Tag(tag: dict, client)[source]

This class represents a Tag object.

str()

Returns name of the tag.

__get__

By it self it returns the name of the tag.

is_nsfw

This function is a coroutine.

Checks if the tag is NSFW (not safe for work).

Returns

bool