This is a python wrapper for my api
api_url = "https://api.dhravya.me/"
This wrapper now has async support, its basically the same except it uses asyncio
Features:
- Generate a qr code for text, url, image, or basically anything, in many different, fancy formats
- OCR: Get text from an image or an image URL
- Meme: Smartly get a meme from any topic (sourced from reddit)
- Basic generators are:
- compliment: returns a compliment
- would you rather: returns a would you rather question
- joke: Returns a (bad) joke
Getting started
- Install the package from pypi
pip install dhravyaAPI
Dependency: requests
pip install --upgrade requests
Usage and examples
Sync(normal)
>>> # Get an 8ball response
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI() # Create a new instance of the API
>>> response = dhravyaapi.eightball()
For OCR:
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI()
>>> text = dhravyapi.ocr(image=BytesIO(open("1u8om0jymh581.jpg", "rb").read()))
>>> # Or, if you have a url:
>>> text = dhravyaapi.ocr(url="https://i.imgur.com/sdfsfXyYsf8Q.jpg")
To get a Meme:
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI()
>>> meme = dhravyaapi.meme(topic="memes")
>>> # Note that this returns a dictionary if url_only is False
To generate a qr code:
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI() # Create a new instance of the API
>>> qr_code= dhravyaapi.qrcode(query="Hello, World!", drawer=1, mask=1)))
>>> # Note that this returns an image object that can be saved to a file
Basic generators:
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI()
>>> compliment = dhravyaapi.compliment()
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI()
>>> wyr = dhravyaapi.wyr()
>>> from dhravyaapi import DhravyaAPI
>>> dhravyaapi = DhravyaAPI()
>>> joke = dhravyaapi.joke()
Async usage:
Its basically the same as synchronised version, except you need to await
every call. example:
QR code:
from dhravyaAPI import AsyncClient
import asyncio
client = AsyncClient(loop=asyncio.get_event_loop())
async def do_stuff():
qr_code = await client.qrcode(query="This is an example", drawer=3)
# Do whatever you want with the qr code
asyncio.get_event_loop().run_until_complete(do_stuff())
Meme example:
from dhravyaAPI import AsyncClient
import asyncio
client = AsyncClient(loop=asyncio.get_event_loop())
async def get_meme():
meme = await client.meme(topic:"python")
print(meme)
asyncio.get_event_loop().run_until_complete(get_meme())