A python library for communicating in the Twitch Messaging Interface (docs)
Unfortunately, I haven't found a good python library for twitch that was simple, extendable, and scalable. Good libraries exist for Javascript (tmi.js), but I haven't found something for Python.
While Python IRC libraries exist (twitch message interface is a weird IRC), most are too complicated to use, not extendable, don't support asyncio, or are for python 2.
Many of the ideas used in this library came from discord.py, a library for creating bots for discord.
This is an example of the core functionality.
import pytmi
config = {
'username': "botname",
'password': "oauthstring",
'channels': ["#channelname"]
}
client = pytmi.TwitchClient()
@client.event
async def on_message(message):
print("Received message")
client.run_sync(**config)
This is an example of the bot command functionality.
from pytmi.bot import TwitchBot
config = {
'username': "botname",
'password': "oauthstring",
'channels': ["#channelname"]
}
client = pytmi.TwitchBot(prefix='!')
@bot.command()
async def hello(ctx):
await ctx.reply("Hello " + ctx.author.name)
client.run_sync(**config)
More examples are available in the examples/ folder.