Clients¶
This module contains all the clients for the library. Each client represents a different endpoint of the API.
Client¶
- class somerandomapi.Client[source]¶
Client for interacting with the Some Random API.
This class provides access to all endpoints of the Some Random API, including both free and premium features.
- Parameters:
session (
aiohttp.ClientSession) –An aiohttp session to use for HTTP requests. If not provided, the client will create and manage its own session.
Changed in version 0.1.0: - If a session is provided, it will not be closed by the client. Otherwise, the client manages its own session. - This parameter can no longer be
None. Either pass a session or omit it entirely.token (str | None) –
The token to use for endpoints that require it.
Added in version 0.1.0.
- property animal¶
The Animal endpoint.
- Type:
- property animu¶
The Animu endpoint.
- Type:
- property canvas¶
The Canvas endpoint.
- Type:
- chatbot(message=None)[source]¶
Chatbot endpoint.
- Parameters:
message (Optional[
str]) – The message to send to the chatbot. If not provided, the Chatbot object will be returned instead which has a send method and supportsasync withelseChatbotResultwill be returned..responseon that is the response from the chatbot.
Example
async with client.chatbot() as bot: await bot.send("Hello!") print(bot.response) # or res = await client.chatbot("Hello!") print(res.response)
- Returns:
The Chatbot object or the ChatbotResult object.
ChatbotResultis returned ifmessageis provided andawaitis used elseChatbot.- Return type:
Union[
Chatbot,ChatbotResult]
- async decode_base64(_input, /)[source]¶
Decode a base64 string.
- Parameters:
input (
str) – The base64 string to decode.- Returns:
Object representing the result of the decoding.
- Return type:
- async decode_binary(_input)[source]¶
Decode a binary string.
- Parameters:
input (
str) – The binary string to decode.- Returns:
Object representing the result of the decoding.
- Return type:
- async encode_base64(_input, /)[source]¶
Encode a string to base64.
- Parameters:
input (
str) – The string to encode.- Returns:
Object representing the result of the encoding.
- Return type:
- async encode_binary(_input, /)[source]¶
Encode a string to binary.
- Parameters:
input (
str) – The string to encode.- Returns:
Object representing the result of the encoding.
- Return type:
- property pokemon¶
The Pokemon endpoint.
- Type:
The Premium endpoint.
- Type:
- async welcome_image(obj=..., *, template=..., type=..., background=..., avatar_url=..., username=..., server_name=..., member_count=..., text_color=..., discriminator=..., key=..., font=...)[source]¶
Generate a welcome image.
- Parameters:
obj (
WelcomeFree) – The object to use. If not passed, the other parameters will be used and a new object will be created.template (Literal[1, 2, 3, 4, 5, 6, 7, 8]) – The template to use. Required if
objis not passed.type (
WelcomeType) – The type of welcome image to generate. Required ifobjis not passed.background (
WelcomeBackground) – The background to use. Required ifobjis not passed.avatar_url (
str) – The avatar URL to use. Required ifobjis not passed.username (
str) – The username to use. Required ifobjis not passed.discriminator (
int) – The discriminator to use.server_name (
str) – The server name to use. Required ifobjis not passed.member_count (
int) – The member count to use. Required ifobjis not passed.text_color (
WelcomeTextColor) – The text color to use. Required ifobjis not passed.key (
str) – The key to use. Required if a key was not passed when creating the client.font (
int) –The font from a predefined list. Choose a number between 0 and 7.
Changed in version 0.1.0: Now takes a range of 1-7 instead of 1-8.
- Return type:
AnimalClient¶
- class somerandomapi.AnimalClient[source]¶
Represents the “Animal” endpoint.
This class is not meant to be instantiated by you. Instead, access it through the
animalattribute of theClientclass.- async get_image_and_fact(animal)[source]¶
Get a random image and fact about an animal.
- async get_image_or_fact(animal)[source]¶
A helper method to get either an image or a fact or both about an animal since the API provides different endpoints for each.
Added in version 0.1.0.
This uses the following methods in order to get the image or fact or both:
And returns an
AnimalImageOrFactobject with the results.
AnimuClient¶
- class somerandomapi.AnimuClient[source]¶
Represents the “Animu” endpoint.
This class is not meant to be instantiated you. Instead, access it through the
animuattribute of theClientclass.- kiss()[source]¶
Shortcut for
get()withAnimu.KISS.- Return type:
- poke()[source]¶
Shortcut for
get()withAnimu.POKE.- Return type:
Chatbot¶
- class somerandomapi.Chatbot[source]¶
A client for the chatbot endpoint.
This is a context manager that should be used with the
async withstatement to ensure the session is closed. Sending a message is done by calling the send method.- async with x
Enters the context manager and returns the client.
- await x(message)
Sends a message to the chatbot and returns the response.
Example
1async with Chatbot(...) as chatbot: 2 # response = await chatbot.send("Hello") is also valid. 3 async with chatbot.send("Hello") as response: 4 print(response.response)
But you can also use it with the
awaitkeyword.1chatbot = Chatbot(...) 2response = await chatbot.send("Hello") 3print(response.response)
Or if you don’t want to use the
.send()method, you can useawaiton the instance of this class directly with the message set on themessageattribute.1chatbot = Chatbot(message="Hello") 2response = await chatbot()
- Parameters:
message (Optional[
str]) – The message to send to the chatbot. This is only used if you use theawaitkeyword on an instance of this class.client (Optional[
Client]) – The client. This is also used a session if you don’t provide one.session (Optional[
aiohttp.ClientSession]) – The session to use. If this is not provided, a new session will be created. You are responsible for closing the session if you provide one.
PokemonClient¶
- class somerandomapi.PokemonClient[source]¶
Represents the “Pokemon” endpoint.
This class is not meant to be instantiated by the user. Instead, access it through the
pokemonattribute of theClientclass.- async get_ability(ability)[source]¶
Get a pokemon ability’s information.
- Parameters:
ability (
str) – The ability name or id of a pokemon ability.- Returns:
Object representing the pokemon ability.
- Return type:
- async get_item(item)[source]¶
Get a pokemon item’s information.
- Parameters:
item (
str) – The Item name or id of a pokemon item.- Returns:
Object representing the pokemon item.
- Return type:
Canvas¶
CanvasClient
- class somerandomapi.CanvasClient[source]¶
Represents the
Canvasendpoint.This class is not meant to be instantiated by you. Instead, access it through the
canvasattribute of theClient.- blue_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.BLUE.- Return type:
- blur_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.BLUR.- Return type:
- blurple2_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.BLURPLE_2.- Return type:
- blurple_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.BLURPLE.- Return type:
- async border(avatar_url, border)[source]¶
Add a border to an image.
- Parameters:
avatar_url (
str) – The avatar URL.border (Union[
CanvasBorder,str]) – The border to add.
- Returns:
The filtered image.
- Return type:
- async brightness_filter(avatar_url, brightness=None)[source]¶
Apply a brightness filter to an image.
- Parameters:
- Returns:
Object representing the filtered image. Use the
.urlattribute to access the image URL.- Return type:
- async color_filter(avatar_url, color=...)[source]¶
Apply a color filter to an image.
- Parameters:
- Returns:
Object representing the filtered image. Use the
.urlattribute to access the image URL.- Return type:
- async colour_filter(avatar_url, colour)[source]¶
Alias for
color_filter().- Return type:
- async colour_viewer(colour=...)[source]¶
Alias for
color_viewer().- Return type:
- async crop(avatar_url, shape)[source]¶
Crop an image into various shapes.
- Parameters:
avatar_url (
str) – The avatar URL.shape (
CanvasCrop) – The shape to apply.
- Returns:
The filtered image.
- Return type:
- async filter(avatar_url, filter)[source]¶
Apply a filter to an image.
- Parameters:
avatar_url (
str) – The URL of the image to apply the filter to.filter (Union[
CanvasFilter,str]) – The filter to apply. Can be aCanvasFilterenum value or a string representing the filter name.
- Returns:
Object representing the filtered image. Use the
.urlattribute to access the image URL.- Return type:
- async generate_genshin_namecard(obj=..., *, avatar_url=..., birthday=..., username=..., description=...)[source]¶
Generate a Genshin Impact namecard.
- Parameters:
obj (
GenshinNamecard) – The object to use. If not provided, a new object will be created with the other parameters.avatar_url (
str) – The avatar URL.birthday (
str) – The birthday. Must be in the formatMM/DD/YYYY.username (
str) – The username.description (Optional[
str]) – An optional description.
- Raises:
TypeError – If
objis not aGenshinNamecard.ValueError – If
avatar_url,birthdayandusername``are not provided and ``objis not passed.
- Returns:
An object representing the generated Genshin Impact namecard. Use the
.urlattribute to access the image URL.- Return type:
- async generate_tweet(obj=..., *, display_name=..., username=..., avatar_url=..., text=..., replies=..., retweets=..., likes=..., theme=TweetTheme.LIGHT)[source]¶
Generate an image of a tweet (or post …).
- Parameters:
obj (
Tweet) – The object to use. If not provided, one will be created with the other parameters.display_name (
str) – The display name of the user.username (
str) – The username of the user.avatar_url (
str) – The avatar URL of the user. Must be .png or .jpg.text (
str) – The text of the tweet. Max 1000 characters.replies (Optional[
int]) – The amount of replies the tweet is supposed to have.retweets (Optional[
int]) – The amount of retweets the tweet is supposed to have.likes (Optional[
int]) – The amount of likes the tweet is supposed to have.theme (
TweetTheme) – The theme of the tweet. Can be either light, dark or dim. Defaults to light.
- Raises:
ValueError – If
display_name,username,avatar_urlandtextare not provided andobjis not passed.
- Returns:
An object representing the generated tweet image. Use the
.urlattribute to access the image URL.- Return type:
- async generate_youtube_comment(obj=..., *, avatar_url=..., username=..., text=...)[source]¶
Generate a Youtube comment image.
- Parameters:
obj (
YoutubeComment) – The object to use. If not provided, a new object will be created with the other parameters.avatar_url (
str) – The avatar URL of the user.username (
str) – The username of the user.text (
str) – The text of the comment.
- Raises:
TypeError – If
objis not aYoutubeComment.ValueError – If
avatar_url,usernameandcommentare not provided andobjis not passed.
- Returns:
An object representing the generated Youtube comment image. Use the
.urlattribute to access the image URL.- Return type:
- green_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.GREEN.- Return type:
- greyscale_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.GREYSCALE.- Return type:
- invert_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.INVERT.- Return type:
- invertgreyscale_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.INVERT_GREYSCALE.- Return type:
- property memes¶
Returns a subclient for the memes endpoints.
- Type:
- async overlay(avatar_url, overlay)[source]¶
Add an overlay to an image.
- Parameters:
avatar_url (
str) – The URL of the image to apply the overlay to.overlay (Union[
CanvasOverlay,str]) – The overlay to apply. Can be aCanvasOverlayenum value or a string representing the overlay name.
- Returns:
Object representing the image with the overlay applied. Use the
.urlattribute to access the image URL.- Return type:
- pixelate_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.PIXELATE.- Return type:
- red_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.RED.- Return type:
- sepia_filter(avatar_url, /)[source]¶
Shortcut for
filter()withCanvasFilter.SEPIA.- Return type:
CanvasMemes
- class somerandomapi.CanvasMemes[source]¶
A class for interacting with the Canvas memes endpoints.
This class is not meant to be instantiated by the user. Instead, access it through the
memesattribute of theCanvasClientclass.