Skip to content
Sayad Uddin Tahsin edited this page Apr 8, 2023 · 1 revision

The Image category provides an easy-to-use interface to retrieve images and save them locally. It allows you to retrieve images such as Bird, Cat, Fox, Raccoon and more. The category provides the ability to get the direct link to the image as well as save the image to your local machine by calling the save_image() function. With this category, you can easily fetch and save images for your project or personal use.

class Bird

Returns an image link of a bird.

Attributes

  • image_link (str): The image link of the bird.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "bird.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "bird.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Bird class
bird = image.Bird()

# Get the image link of a bird
image_link = bird.image_link

# Save the bird image
bird.save_image("my_bird.png")

class Cat

Returns an image link of a cat.

Attributes

  • image_link (str): The image link of the cat.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "cat.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "cat.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Cat class
cat = image.Cat()

# Get the image link of a cat
image_link = cat.image_link

# Save the cat image
cat.save_image("my_cat.png")

class Dog

Returns an image link of a dog.

Attributes

  • image_link (str): The image link of the dog.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "dog.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "dog.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Dog class
dog = image.Dog()

# Get the image link of a dog
image_link = dog.image_link

# Save the dog image
dog.save_image("dog.png")

class Fox

Returns an image link of a fox.

Attributes

  • image_link (str): The image link of the fox.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "fox.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "fox.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Fox class
fox = image.Fox()

# Get the image link of a fox
image_link = fox.image_link

# Save the fox image
fox.save_image("fox.png")

class Kangaroo

Returns an image link of a kangaroo.

Attributes

  • image_link (str): The image link of the kangaroo.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "kangaroo.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "kangaroo.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Kangaroo class
kangaroo = image.Kangaroo()

# Get the image link of a kangaroo
image_link = kangaroo.image_link

# Save the kangaroo image
kangaroo.save_image("kangaroo.png")

class Koala

Returns an image link of a koala.

Attributes

  • image_link (str): The image link of the koala.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "koala.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "koala.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Koala class
koala = image.Koala()

# Get the image link of a koala
image_link = koala.image_link

# Save the koala image
koala.save_image("koala.png")

class Panda

Returns an image link of a panda.

Attributes

  • image_link (str): The image link of the panda.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "panda.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "panda.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Panda class
panda = image.Panda()

# Get the image link of a panda
image_link = panda.image_link

# Save the panda image
panda.save_image("my_panda_img.png)

class Pikachu

Returns an image link of a pikachu.

Attributes

  • image_link (str): The image link of the pikachu.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "pikachu.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "pikachu.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Pikachu class
pikachu = image.Pikachu()

# Get the image link of a pikachu
image_link = pikachu.image_link

# Save the pikachu image
pikachu.save_image("my_pikachu.png")

class Raccoon

Returns an image link of a raccoon.

Attributes

  • image_link (str): The image link of the raccoon.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "raccoon.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "raccoon.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Raccoon class
raccoon = image.Raccoon()

# Get the image link of a raccoon
image_link = raccoon.image_link

# Save the raccoonimage
raccoon.save_image("my_raccoon.png")

class RedPanda

Returns an image link of a red panda.

Attributes

  • image_link (str): The image link of the red panda.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "red panda.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "red panda.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the RedPanda class
red_panda = image.RedPanda()

# Get the image link of a bird
image_link = red_panda.image_link

# Save the red panda image
red_panda.save_image("my_red_panda.png")

class Whale

Returns an image link of a whale.

Attributes

  • image_link (str): The image link of the whale.
  • raw (dict): The raw JSON response from the API.

Exceptions

  • APITimeout: Raised when the API takes too long to respond.
  • APIError: Raised when the API returns an error.

save_image(name: str = "whale.png")

Saves the image.

Parameters

  • name (str, optional): Image name/path. Defaults to "whale.png".
Returns
  • bool: Returns True if the image was successfully saved.

Exceptions

Example

from sra import image

# Create a new instance of the Whale class
whale = image.Whale()

# Get the image link of a whale
image_link = whale.image_link

# Save the whale image
whale.save_image("my_whale.png")
Clone this wiki locally