7TV EventAPI Wrapper
This is a Python wrapper for the 7TV EventAPI, which provides async access to the websocket events on their Emote Platform.
Requirements
- Python 3.8 or higher
Installation
You can install the 7TV EventAPI Wrapper using pip. Open your terminal and run the following command:
pip install eventapi
Usage
Here's a simple example of how to use wrapper:
import asyncio
from eventapi.EventApi import EventApi
from eventapi.WebSocket import (
EventType,
ResponseTypes,
SubscriptionCondition,
SubscriptionData,
)
async def callback(data: ResponseTypes):
print("Message from callback: ", data)
async def main():
# create instance of EventApi with message callback
app = EventApi(callback=callback)
# connect to websocket
await app.connect()
print("Connected")
# create subscription with specified condition
condition = SubscriptionCondition(object_id="6433b7cec07d26f890dd2d01")
subscription = SubscriptionData(
subscription_type=EventType.EMOTE_SET_ALL, condition=condition
)
await app.subscribe(subscription_data=subscription)
# you can also use async iterator without specifying callback
async for message in app:
print("Message from async iterator: ", message)
# run forever if we are not using async for
await asyncio.Future()
asyncio.run(main())
Discord.py / Pycord example:
from typing import Any, Dict, List
import aiohttp
import discord
from eventapi.EventApi import EventApi
from eventapi.WebSocket import (
Dispatch,
EventType,
ResponseTypes,
SubscriptionCondition,
SubscriptionData,
)
async def format_url(data: Dict[str, Any]) -> str:
base_url = "https://cdn.7tv.app/emote/{}/4x".format(data.get("id"))
if "animated" not in data:
async with aiohttp.ClientSession() as cs:
async with cs.get(base_url + ".gif") as r:
if r.status == 200:
base_url += ".gif"
else:
if data.get("animated"):
base_url += ".gif"
return base_url
async def callback(data: ResponseTypes) -> None:
if not isinstance(data, Dispatch):
return
if data.type != EventType.EMOTE_SET_UPDATE:
return
channel = client.get_channel(927288026000945162) # your channel id
changes: List[discord.Embed] = []
def add_change(description: str, color: discord.Color, image_url: str):
changes.append(
discord.Embed(description=description, color=color).set_image(url=image_url)
)
if data.body.pulled:
for pulled in data.body.pulled:
add_change(
"**Deleted emote:** `{}`".format(pulled.old_value.get("name")),
discord.Color.brand_red(),
await format_url(pulled.old_value),
)
if data.body.pushed:
for pushed in data.body.pushed:
add_change(
"**Added emote:** `{}`".format(pushed.value.get("name")),
discord.Color.brand_green(),
await format_url(pushed.value.get("data")),
)
if data.body.updated:
for updated in data.body.updated:
add_change(
"**Edited emote:** `{}` » `{}`".format(
updated.old_value.get("name"), updated.value.get("name")
),
discord.Color.yellow(),
await format_url(updated.value),
)
if len(changes) > 0:
await channel.send(embeds=changes)
intents = discord.Intents.default()
client = discord.Client(intents=intents)
client.eventapi = EventApi(callback=callback)
@client.listen("on_ready", once=True)
async def on_ready():
await client.eventapi.connect()
condition = SubscriptionCondition(
object_id="6433b7cec07d26f890dd2d01"
) # your emote-set id
subscription = SubscriptionData(
subscription_type=EventType.EMOTE_SET_ALL, condition=condition
)
await client.eventapi.subscribe(subscription_data=subscription)
client.run("your token here") # your token
Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
License
This project is licensed under the MIT License.
Metadata
Release files for eventapi 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| eventapi-1.1.2.tar.gz | 10.1 kB | Without provenance | Details for eventapi-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| eventapi-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for eventapi-1.1.2-py3-none-any.whl |
Total release size: 19.1 kB
Release files / eventapi-1.1.2.tar.gz
| Download URL | eventapi-1.1.2.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a43411b7b6c85e04524d642f4745ba6c54097d80772072ccc43a1875a2185810
|
|
BLAKE2b-256 checksum How to use checksums |
49e4853f0babd557085d77e584db560362ff5ebfba65cdc1070a63bcb2ec7b59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Release files / eventapi-1.1.2-py3-none-any.whl
| Download URL | eventapi-1.1.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c6441743ebad38bb43d2a9a8a6e87ab382e3adb89cef6b36f083c10c6aedd6f
|
|
BLAKE2b-256 checksum How to use checksums |
0c8618fead10aaadb3d42d72792c97dbabe3f08afa8d2c880f5e5ed4ced7d9fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Security for eventapi 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.