Skip to main content

A Python SDK for the Imgur API.

Project description

PyImgurAPI

PyPI Python Version

A Python SDK for the Imgur API.

Overview

The package is supposed to be in strict accordance with the Imgur's documentation, i.e. description for any endpoint implemented in the SDK can also be found there.

The package does not have any third-party dependencies; it requires only Python 3.7+.

Alternatives:

  • PyImgur was originally an official client for Imgur, but it seems to be deprecated now.
  • imgur-python a relevant unofficial SDK for Imgur.

Installation

Using pip:

$ pip install pyimgurapi

First authentication

  1. Register your application to get client_id and client_secret.
  2. Open the next URL in a browser: https://api.imgur.com/oauth2/authorize?client_id=<your_client_id>&response_type=token (replace <your_client_id> with the actual ID)
  3. Allow authentication for a client.
  4. Copy the refresh_token value from the URL field.
  5. Then you can authenticate your client:
from pyimgurapi import ImgurAPI


api = ImgurAPI(
    refresh_token="<refresh_token>",
    client_id="<client_id>",
    client_secret="<client_secret>",
)
api.auth()

Basic usage

Getting info about an image:

from pyimgurapi import ImgurAPI


api = ImgurAPI(
    refresh_token="<refresh_token>",
    client_id="<client_id>",
    client_secret="<client_secret>",
)
api.auth()

meme_image = api.image.get_image("6yHmlwT")

Then you can access attributes of the response using a dot-notation:

print(meme_image.data.link)

or using a subscript-notation:

print(meme_image["data"]["link"])

Uploading a new image:

from pyimgurapi import ImgurAPI


api = ImgurAPI(
    refresh_token="<refresh_token>",
    client_id="<client_id>",
    client_secret="<client_secret>",
)
api.auth()

filename = "cat1.jpg"
with open(filename, 'rb') as f:
    new_image = api.image.upload(
        f,
        filename,
        title="New image",  # optional
        description="Absolutely new image"  # optional
    )

Then you can access attributes of the new image as well:

print(new_image.data.link)

Contributing

See the contributing guidelines.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyimgurapi-0.5.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

pyimgurapi-0.5.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file pyimgurapi-0.5.0.tar.gz.

File metadata

  • Download URL: pyimgurapi-0.5.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Windows/10

File hashes

Hashes for pyimgurapi-0.5.0.tar.gz
Algorithm Hash digest
SHA256 06f688b5189f37ab830a2f18ade2027e4acbe2e66728950ddcac9618f6df75c5
MD5 9518df0f0d1cedbdb333b2610e4cdd41
BLAKE2b-256 d38df7c9eed65ce54149d30e5b4b04a09d84392cbfb7dd36cd67db75d3404a65

See more details on using hashes here.

File details

Details for the file pyimgurapi-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pyimgurapi-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Windows/10

File hashes

Hashes for pyimgurapi-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e55fa07cc9b8af65547ec98c3fdb8e368401a8a49c6ba3b86cc6ff308610d25b
MD5 90b10d634a88b6244997fe5ad081f967
BLAKE2b-256 4d28ae2b12b40e7672b1e7d1d932388e080cf79df5b8f601e87a6d2ff5500914

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page