TMI (Twitch Messaging Interface) library for Python.
You can get your OAuth token with the site https://twitchapps.com/tmi/
.
Here's a little application that logs in the user using OAuth, joins the Twitch channel requested by the user, sends the message Hello, Twitch!
to the chat and then leaves the channel.
import asyncio
import pytmi
async def main() -> None:
nick = input("Insert your Twitch nickname: ").strip()
token = input("Insert your Twitch OAuth token: ").strip()
channel = input("Insert the channel to join: ").strip()
async with pytmi.Client() as client:
await client.login_oauth(token, nick, channel)
await client.join(channel)
await client.send_message("Hello, Twitch!")
if __name__ == "__main__":
try:
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
except:
print("Something went wrong.")
You can find others usage example inside the test
directory.
-
Spurious errors when using SSL.
-
Possible problems with pending tasks (if you don't cleanup them properly).
-
Handle connection and login error in a better way.
-
Handle messages that are not correctly encoded in UTF8.
-
Major version bump.
-
Add a background task that collects messages in a buffer and sends pong as needed.
-
Rewrite Client code.
-
Change methods name (
part
->leave
,privmsg
->send_message
). -
Add async context manager (
async with
) support for Client.
-
Major library simplification and rewriting.
-
Removed buggy background task.
-
Add library logging.
-
Add background task to collect messages (removed in
v0.3.0
). -
Refactor code.
-
Add message buffer abstraction.
-
Major code refactoring.
- Minor code refactoring.
-
Rewrite library to be asynchronous.
-
Add SSL support (enabled by default).
-
Reorganize project structure.
-
Minor code refactoring.
-
Improve message handling and parsing.
- Initial version.