Socket
Socket
Sign inDemoInstall

pyimgurapi

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyimgurapi

A Python SDK for the Imgur API.


Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc