The simple way of using Imgur.
You can upload images, download images, read comments, update your albums, message people and more. In fact, you can do almost everything via PyImgur that you can via the webend.
Installation
The recommended way to install is via pip
$ pip install pyimgur
Getting Started
Before we can start using PyImgur, we need to register our application with Imgur. This way, Imgur can see what each application is doing on their site. Go to https://api.imgur.com/oauth2/addclient to register your client. Note that you can’t use an application registration for the old v2 version of the Imgur API, which was depreciated December 2012.
When we registered our application we got a client_id and a client_secret. The client_secret is used for authenticating as a user, if we just need access to public or anonymous resources, then we can leave it out. For our first example we’re going to get some information about an image already uploaded to image:
import pyimgur
CLIENT_ID = "Your_applications_client_id"
im = pyimgur.Imgur(CLIENT_ID)
image = im.get_image('S1jmapR')
print(image.title) # Cat Ying & Yang
print(image.link) # http://imgur.com/S1jmapR.jpg
The Imgur object keeps the authentication information, changes authentication and is the common way to get objects from Imgur.
Uploading an Image
Let’s use another example to show how to upload an image:
import pyimgur CLIENT_ID = "Your_applications_client_id" PATH = "A Filepath to an image on your computer" im = pyimgur.Imgur(CLIENT_ID) uploaded_image = im.upload_image(PATH, title="Uploaded with PyImgur") print(uploaded_image.title) print(uploaded_image.link) print(uploaded_image.size) print(uploaded_image.type)
Some methods here one or more arguments with the default value None. For methods modifying existing objects, this mean to keep the already existing value. For methods not modifying existing objects, this mean to use the Imgur default.
Lazy objects
To reduce the load on Imgur, PyImgur only requests the data it needs. This means each object has the attribute _has_fetched which if True` has fetched all the data it can, if False it can fetch more information.
Whenever we request an attribute that hasn’t been loaded the newest information will be requested from Imgur and all the object attributes will be updated to the newest values. We can also use the method refresh() to force a call to Imgur, that will update the object with the latest values:
import pyimgur
CLIENT_ID = "Your_applications_client_id"
im = pyimgur.Imgur(CLIENT_ID)
gallery_image = im.get_gallery_image('JiAaT')
author = gallery_image.author
print(author._has_fetched) # False ie. it's a lazily loaded object
print(author.reputation)
print(author._has_fetched) # True ie. all values have now been retrieved.
Introspection
Remember that as usual you can use the dir, vars and help builtin functions to introspect objects to learn more about them and how they work.
Mashape API
Imgur supports commercial use via Mashape, which uses a different endpoint and some additional authentication. You can enable this easily by providing your Mashape key on initialization of the Imgur object:
import pyimgur CLIENT_ID = "Your_applications_client_id" MASHAPE_KEY = "Your_mashape_api_key" im = pyimgur.Imgur(CLIENT_ID, mashape_key=MASHAPE_KEY)
More information on Mashape’s API and Pricing can be found on the Mashape website.
Support
If you find an bug, have any questions about how to use PyImgur or have suggestions for improvements then feel free to file an issue on the Github project page.
Documentation
PyImgur’s full documentation is located on ReadTheDocs.
License
All of the code contained here is licensed by the GNU GPLv3.
Metadata
Release files for ppyimgur 0.6.0.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ppyimgur-0.6.0.post1.tar.gz | 33.0 kB | Without provenance | Details for ppyimgur-0.6.0.post1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ppyimgur-0.6.0.post1-py3-none-any.whl | Python 3 | none | any | Details for ppyimgur-0.6.0.post1-py3-none-any.whl |
Total release size: 53.2 kB
Release files / ppyimgur-0.6.0.post1.tar.gz
| Download URL | ppyimgur-0.6.0.post1.tar.gz |
|---|---|
| Size | 33.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad7352356696a72ee408e4cb0de08410f49617e74db340e6a7f733e2a8b5b99a
|
|
BLAKE2b-256 checksum How to use checksums |
b325b4116e2efcb28b637cd347e26ae534c0510682a87cddf9574c0bfd809d28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / ppyimgur-0.6.0.post1-py3-none-any.whl
| Download URL | ppyimgur-0.6.0.post1-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
deb7be03a75450704532135cb874a5d4c76cc94b9d2f391f35994d5e3a09c9fb
|
|
BLAKE2b-256 checksum How to use checksums |
50877249b156cd7b925e78c0cd1fb39533f3af9dfb276590e1345fc5d9c43168
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ppyimgur 0.6.0.post1
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.