SkillAgentSearch skills...

Imgbb

A simple tool enabling you to asynchronously upload images to imgbb.

Install / Use

/learn @extr3mis/Imgbb

README

imgbb

<img src='https://img.shields.io/badge/Python-3.5+-blue'> <img src='https://img.shields.io/badge/license-MIT-green'> <img src='https://img.shields.io/badge/async-enabled-blue'> <img src='https://www.code-inspector.com/project/10298/score/svg'>

A simple tool enabling you to asynchronously upload images to <a href='https://www.imgbb.com'>imgbb</a>. 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'))

Related Skills

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated4y ago
Forks1

Languages

Python

Security Score

75/100

Audited on Mar 19, 2022

No findings