Home

Awesome

The imgurpython project is no longer supported.

imgurpython

A Python client for the Imgur API. It can be used to interact with the Imgur API in your projects.

You must register your client with the Imgur API, and provide the Client-ID to make any request to the API (see the Authentication note). If you want to perform actions on accounts, the user will have to authorize your application through OAuth2.

Requirements

Imgur API Documentation

Our developer documentation can be found here.

Community

The best way to reach out to Imgur for API support is emailing us at api@imgur.com.

Installation

pip install imgurpython

Library Usage

Using imgurpython in your application takes just a couple quick steps.

To use the client from a strictly anonymous context (no actions on behalf of a user)


from imgurpython import ImgurClient

client_id = 'YOUR CLIENT ID'
client_secret = 'YOUR CLIENT SECRET'

client = ImgurClient(client_id, client_secret)

# Example request
items = client.gallery()
for item in items:
    print(item.link)

To initialize a client that takes actions on behalf of a user

from imgurpython import ImgurClient

client_id = 'YOUR CLIENT ID'
client_secret = 'YOUR CLIENT SECRET'

client = ImgurClient(client_id, client_secret)

# Authorization flow, pin example (see docs for other auth types)
authorization_url = client.get_auth_url('pin')

# ... redirect user to `authorization_url`, obtain pin (or code or token) ...

credentials = client.authorize('PIN OBTAINED FROM AUTHORIZATION', 'pin')
client.set_user_auth(credentials['access_token'], credentials['refresh_token'])

or if you already have an access/refresh token pair you can simply do

from imgurpython import ImgurClient

# If you already have an access/refresh pair in hand
client_id = 'YOUR CLIENT ID'
client_secret = 'YOUR CLIENT SECRET'
access_token = 'USER ACCESS TOKEN'
refresh_token = 'USER REFRESH TOKEN'

# Note since access tokens expire after an hour, only the refresh token is required (library handles autorefresh)
client = ImgurClient(client_id, client_secret, access_token, refresh_token)

Error Handling

Error types

from imgurpython.helpers.error import ImgurClientError

try
    ...
except ImgurClientError as e
    print(e.error_message)
    print(e.status_code)

Credits

To view client and user credit information, use the credits attribute of ImgurClient. credits holds a dictionary with the following keys:

For more information about rate-limiting, please see the note in our docs!

Examples

Examples can be found here

ImgurClient Functions

Account

Album

Comment

Custom Gallery

Gallery

Image

Conversation

Notification

Memegen

Imgur entry points

entry pointcontent
imgur.com/{image_id}image
imgur.com/{image_id}.extensiondirect link to image (no html)
imgur.com/a/{album_id}album
imgur.com/a/{album_id}#{image_id}single image from an album
imgur.com/gallery/{gallery_post_id}gallery