The simple way of using Imgur.

Overview

PyImgur

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.

Owner
Andreas Damgaard Pedersen
Andreas Damgaard Pedersen
Python-based Snapchat score booster using pyautogui module

Snapchat Snapscore Botter Python-based Snapchat score booster using pyautogui module. Click here to report bugs. Usage Download ZIP here and extract t

477 Dec 31, 2022
An interactive and multi-function Telegram bot, made especially for Telegram groups.

PyKorone An interaction and fun bot for Telegram groups, having some useful and other useless commands. Created as an experiment and learning bot but

Amano Team 17 Nov 12, 2022
Popcorn-time-api - Python API for interacting with the Popcorn Time Servers

Popcorn Time API 📝 CONTRIBUTIONS Before doing any contribution read CONTRIBUTIN

Antonio 3 Oct 31, 2022
🔮 A usefull set of scripts to dig into your Discord data package.

Discord DataExtractor 🔮 Discord DataExtractor is a set of scripts that allows you to dig into your Discord Data package. Repository guide ☕ Coffee_Ga

3 Dec 29, 2021
This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

Alec Ibarra 1 Mar 03, 2022
Pythonic event-processing library based on decorators

Process Events In Style This library aims to simplify the common pattern of event processing. It simplifies the process of filtering, dispatching and

Nicolas Marier 3 Sep 01, 2022
An advanced api client for python botters.

[ALPHA] pybotters An advanced api client for python botters. 📌 Description pybottersは仮想通貨botter向けのPythonライブラリです。複数取引所に対応した非同期APIクライアントであり、bot開発により素晴ら

261 Dec 31, 2022
Surfline Forecast Bot For Python

Surfline Forecast Bot A telegram bot created using Telethon that allows users to

1 May 08, 2022
AWS Lambda - Parsing Cloudwatch Data and sending the response via email.

AWS Lambda - Parsing Cloudwatch Data and sending the response via email. Author: Evan Erickson Language: Python Backend: AWS / Serverless / AWS Lambda

Evan Scott Erickson 1 Nov 14, 2021
Yes, it's true :purple_heart: This repository has 353 stars.

Yes, it's true! Inspired by a similar repository from @RealPeha, but implemented using a webhook on AWS Lambda and API Gateway, so it's serverless! If

510 Dec 28, 2022
Discord bot that displays the current Swatch Internet Time (.beat) as a status.

Internet-Time-Display Discord bot that displays the current Swatch Internet Time (.beat) as a status. Visit the website! Add the bot to your server! A

2 Mar 15, 2022
Ivan Telegram Userbot with python

Riviani Ramadhan Ivan-Ubot Pada Dasarnya Ivan-Ubot adalah userbot Telegram modular yang berjalan di Python3 dengan database sqlalchemy. Berbasis Paper

1 Oct 29, 2021
Get random jokes bapack2 from jokes-bapack2-api

Random Jokes Bapack2 Get random jokes bapack2 from jokes-bapack2-api Requirements Python Requests HTTP library How to Run py random-jokes-bapack2.py T

Miftah Afina 1 Nov 18, 2021
python library to the bitly api

bitly API python library Installation pip install bitly_api Run tests Your username is the lowercase name shown when you login to bitly, your access

Bitly 245 Aug 14, 2022
Vladilena Mirize Music - Bot Music Telegram By @zenfrans

Vladilena Mirize Music - Bot Music Telegram By @zenfrans

Wahyusaputra 3 Feb 12, 2022
A decentralized messaging daemon built on top of the Kademlia routing protocol.

parakeet-message A decentralized messaging daemon built on top of the Kademlia routing protocol. Now that you are done laughing... pictures what is it

Jonathan Abbott 3 Apr 23, 2022
💻 Discord-Auto-Translate-Bot - If you type in the chat room, it automatically translates.

💻 Discord-Auto-Translate-Bot - If you type in the chat room, it automatically translates.

LeeSooHyung 2 Jan 20, 2022
WhatsAppCrashingToolv1.1 - WhatsApp Crashing Tool v1.1

WhatsAppCrashingTool v1.1 This is just for Educational Purpose WhatsApp Crashing

E4crypt3d 3 Dec 20, 2022
Python bindings to the Syncthing REST interface.

python-syncthing Python bindings to the Syncthing REST interface. Python API Documentation Syncthing Syncthing REST Documentation Syncthing Forums $ p

Blake VandeMerwe 64 Aug 13, 2022
A Discord bot that rewards players in Minecraft for sending messages on Discord

MCRewards-Discord-Bot A Discord bot that rewards players in Minecraft for sending messages on Discord How to setup: Download this git as a .zip, or cl

3 Dec 26, 2021