Skip to main content

pymgflip

A type-safe Python client for the Imgflip meme generation API.

Features

  • Full type hints and type safety
  • Support for all Imgflip API endpoints
  • Automatic handling of authentication
  • Graceful handling of premium-only features
  • Comprehensive error handling
  • Easy to use interface

Installation

pip install pymgflip

Quick Start

from pymgflip import Client

# Get popular meme templates (no auth required)
client = Client()
memes = client.get_memes()

for meme in memes[:5]:
    print(f"{meme.name}: {meme.id}")

Authentication

Most endpoints require authentication with your Imgflip account:

from pymgflip import Client

client = Client(username="your_username", password="your_password")

# Create a meme
result = client.caption_image(
    template_id="61579",  # "One Does Not Simply" template
    text0="One does not simply",
    text1="Use the Imgflip API without pymgflip"
)

if result.success:
    print(f"Meme created: {result.url}")

API Endpoints

Free Endpoints

get_memes() - No authentication required

Get popular meme templates:

client = Client()
memes = client.get_memes()

caption_image() - Requires authentication

Add captions to a meme template:

client = Client(username="...", password="...")
result = client.caption_image(
    template_id="61579",
    text0="Top text",
    text1="Bottom text",
    font="impact",  # default
    max_font_size=50,
)

Premium Endpoints

These endpoints require a premium Imgflip account ($9.99/month):

search_memes()

Search for meme templates:

memes = client.search_memes(query="drake", include_nsfw=False)

caption_gif()

Caption animated GIF templates:

result = client.caption_gif(
    template_id="gif_template_id",
    boxes=[
        {"text": "First frame text"},
        {"text": "Second frame text"},
    ]
)

automeme()

Automatically generate a meme from text:

result = client.automeme(text="When the code works on the first try")

ai_meme()

Generate memes using AI:

result = client.ai_meme(
    model="openai",  # or "classic"
    prefix_text="When you realize",
    template_id="optional_specific_template"
)

Error Handling

The library provides specific exceptions for different error cases:

from pymgflip import Client
from pymgflip.exceptions import (
    AuthenticationError,
    PremiumRequiredError,
    APIError,
    NetworkError
)

client = Client(username="...", password="...")

try:
    result = client.search_memes("drake")
except AuthenticationError:
    print("Invalid username or password")
except PremiumRequiredError:
    print("This feature requires a premium account")
except NetworkError:
    print("Network connection failed")
except APIError as e:
    print(f"API error: {e}")

Premium Detection

The client automatically detects if an account has premium access:

client = Client(username="...", password="...")

# Try to use a premium feature
try:
    client.search_memes("test")
except PremiumRequiredError:
    pass

# Check premium status
if client.is_premium is False:
    print("Account does not have premium access")

Advanced Usage

Custom Text Boxes

For advanced meme layouts with custom positioned text:

result = client.caption_image(
    template_id="61579",
    boxes=[
        {
            "text": "Custom text",
            "x": 10,
            "y": 10,
            "width": 100,
            "height": 25,
            "color": "#ffffff",
            "outline_color": "#000000"
        }
    ]
)

Remove Watermark (Premium)

result = client.caption_image(
    template_id="61579",
    text0="Top text",
    text1="Bottom text",
    no_watermark=True  # Premium only
)

Context Manager

Use the client as a context manager for automatic cleanup:

with Client(username="...", password="...") as client:
    memes = client.get_memes()
    # Client automatically closes connections when done

Testing

Run tests with pytest:

# Install dev dependencies
pip install -e ".[dev]"

# Run unit tests
pytest

# Run integration tests (requires real API)
pytest -m integration

# Run with coverage
pytest --cov=pymgflip

Environment Variables

For testing with real credentials:

export IMGFLIP_USERNAME="your_username"
export IMGFLIP_PASSWORD="your_password"
pytest tests/test_integration.py -m integration

Requirements

  • Python 3.8+
  • httpx
  • pydantic

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for pymgflip 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymgflip 0.1.1
File Size Uploaded Provenance
pymgflip-0.1.1.tar.gz 79.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pymgflip 0.1.1
File Interpreter ABI Platform
pymgflip-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 87.7 kB

Release files / pymgflip-0.1.1.tar.gz

Download URL pymgflip-0.1.1.tar.gz
Size 79.1 kB
Tags Source
SHA-256 checksum
How to use checksums
370f654f3a7addacb76cf8ec3f6a524bee31269210babcca3c2b6fe6a315b50b
BLAKE2b-256 checksum
How to use checksums
d4476648959691be13bab5daf28cfef343ebfc3f7ddae1e49947108c7368309c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / pymgflip-0.1.1-py3-none-any.whl

Download URL pymgflip-0.1.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a192bd2f89a821149028582d0dfd7d136fafe54f06b6b378a2fd855de2ef65da
BLAKE2b-256 checksum
How to use checksums
cb7b05e2af1b9c5542052643357041647e99f49ee72c04f4262d14380d90f401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Security for pymgflip 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page