Reference

The main class

class imgflip.Imgflip(username, password, session=None)

The main Imgflip class

Parameters
  • username (str) – your imgflip username

  • password (str) – your imgflip password

  • session (Optional[Union[requests.sessions.Session, aiohttp.client.ClientSession]]) – the session which will be used by the class. If it is requests.Session, the methods of this would be sync and if aiohttp.ClientSession, the methods would be async.

Raises

TypeError – if the session is not requests.Session or aiohttp.ClientSession

popular_memes(limit=100, dictionary=True)
This function is a coroutine if the session is aiohttp.ClientSession
Get the most popular meme templates from imgflip based on how many times they get captioned.
Parameters
  • limit (Optional[int]) – the amount of templates you want. Defaults to 100. You can only get upto 100 popular meme templates.

  • dictionary (bool) –

    If True, it will return a dict with template names as keys and Template objects as values

    If False, it will return a list of Template objects.

Returns

the popular meme templates

Return type

Union[List[Template], Dict[str, Template]]

make_meme(template, font='impact', max_font_size=50, top_text=None, bottom_text=None, boxes=None)
This function is a coroutine if the session is aiohttp.ClientSession
Creates a meme.
Parameters
  • template (Union[int, Template]) – the template to use for the meme. You can pass the template id here.

  • font (Literal["impact", "arial"]) – the font to use for the text. Defaults to impact.

  • max_font_size (Optional[int]) – the maximum font size of the text

  • top_text (Optional[str]) – the text at the top (or the text for the first box) of the meme

  • bottom_text (Optional[str]) – the text at the bottom (or the text for the second box) of the meme

  • boxes (Optional[List[Box]]) – the text boxes to use in the meme

Note

if you use top_text/bottom_text and boxes together, boxes would be used in making the meme.

Raises

ImgflipError – Something went wrong while making the meme.

Returns

the meme which has been created in imgflip

Return type

Union[SyncMeme, AsyncMeme]

create(*args, **kwargs)

alias for make_meme

make(*args, **kwargs)

alias for make_meme

Objects

class imgflip.Meme(template_id, url, page_url, session)
Base class for SyncMeme and AsyncMeme
str(Meme_object) would return the image url of the meme.
template_id

the id of the meme template

Type

int

url

the image url of the meme

Type

str

page_url

the url of the imgflip page of the meme

Type

str

class imgflip.SyncMeme(template_id, url, page_url, session)

This is a subclass of Meme. It is returned in make_meme() when the session passed is requests.Session

read()

Reads the meme and get the bytes of the image

Returns

the image of the meme in bytes

Return type

bytes

save(fp)

Saves the meme image in a file. This returns nothing.

Parameters

fp (os.PathLike) – the file path to save the image to.

class imgflip.AsyncMeme(template_id, url, page_url, session)

This is a subclass of Meme. It is returned in make_meme() when the session passed is aiohttp.ClientSession

async read()
This function is a coroutine
Reads the meme and get the bytes of the image
Returns

the image of the meme in bytes

Return type

bytes

async save(fp)
This function is a coroutine
Saves the meme image in a file.
Parameters

fp (os.PathLike) – the file path to save the image to.

class imgflip.Box(text, position, size, color='#ffffff', outline_color='#000000')
Represents a text box that can be used in the boxes parameter of make_meme().
str(box_obj) will return the text of the box.
Parameters
  • text (str) – the text on the box

  • position (Tuple[int, int]) – the position of the box on the meme in the format (x, y)

  • size (Tuple[int, int]) – the size of the box in the format (width, height)

  • color (Optional[str]) – the hex color of the text on the box. Defaults to "#ffffff"

  • outline_color (Optional[str]) – the outline hex color of the text on the box. Defaults to "#000000"

class imgflip.Template(id, name=None, url=None, width=None, height=None, box_count=None)
Represents a meme template which can be passed into make_meme().
int(template_obj) will return the id of the template.
str(template_obj) will return the name of the template.
id

the template id

Type

int

name

the name of the template

Type

Optional[str]

url

the image url of the template

Type

Optional[str]

width

the width of the template image

Type

Optional[int]

height

the height of the template image

Type

Optional[int]

box_count

the number of boxes in the template

Type

Optional[int]

Exceptions

exception imgflip.ImgflipError

The exception that is raised when making the meme fails.