Examples¶
These examples demonstrate how to use the Cookie API.
The API key should be defined in a .env file in the root of the project.
.env¶
COOKIE_KEY=# Your API key
Sync¶
from cookie import CookieAPI
api = CookieAPI() # API key is set in .env
user_stats = api.get_user_stats(123456789) # Replace with user ID
print(user_stats)
Async¶
import asyncio
from cookie import AsyncCookieAPI
api = AsyncCookieAPI() # API key is set in .env
async def main():
async with api as con:
user_stats = await con.get_user_stats(123456789) # Replace with user ID
print(user_stats)
asyncio.run(main())
Images¶
Retrieve images and use them with the pillow library.
import io
from PIL import Image
from cookie import CookieAPI
api = CookieAPI() # API key is set in .env
user_stats = api.get_guild_image(1010915072694046794) # Your guild ID
img = Image.open(io.BytesIO(user_stats))
img.show()