Skip to content

Latest commit

 

History

History
50 lines (42 loc) · 1.7 KB

README.md

File metadata and controls

50 lines (42 loc) · 1.7 KB

imgbb

A simple tool enabling you to asynchronously upload images to imgbb. Requires Python 3.5+

Installation

Install this package using pip.

$ pip install git+https://github.com/extr3mis/imgbb.git

Usage

Import the package using the given import statement.

$ from imgbb.client import Client

Now you can make a Client object and initialize it with your own API key from imgbb. Optionally, also pass the aiohttp.ClientSession() object you want the imgbb client to use.

$ myclient = Client(api_key_here)

Now you can use your Client to upload an image using the Client.post() method. Since Client.post() is a coroutine make sure to await it. Catch the response from the request in request.

$ response = await myclient.post('/path_to_image/image.jpg','name')

Now you can get the URL to the image you've just uploaded using response['data']['url'].

$ URL = response['data']['url']

Quick Example

from imgbb.client import Client
import os
import aiohttp
import asyncio
key = os.getenv('IMGBB_API_KEY')
session = aiohttp.ClientSession()
myclient = Client(key,session)

async def upload(image,name):
    response = await myclient.post(image,name)
    url = response['data']['url']
    print(f'Uploaded image URL: {url}')

if __name__=='__main__':
    asyncio.run(upload('image.jpg','Cool picture'))