Get real time Twitch/Youtube events through Streamlabs Socket API
Go to file
2022-11-13 12:58:18 +00:00
streamlabsio remove pretty print 2022-11-13 12:55:28 +00:00
__main__.py initial commit 2022-11-13 10:07:08 +00:00
.gitignore initial commit 2022-11-13 10:07:08 +00:00
LICENSE Initial commit 2022-11-13 08:17:36 +00:00
poetry.lock initial commit 2022-11-13 10:07:08 +00:00
pyproject.toml add readme, repo to pyproject.toml 2022-11-13 12:58:18 +00:00
README.md Update README.md 2022-11-13 10:39:28 +00:00

PyPI version License: MIT Code style: black Imports: isort

A Python client for Streamlabs SocketIO API

Requirements

  • A Streamlabs SocketIO API key.
    • You can acquire this by logging into your Streamlabs.com dashboard then Settings->Api Settings->API Tokens

How to install using pip

pip install streamlabsio

How to Use

You may store your api key in a config.toml file, its contents should resemble:

[streamlabs]
token = "<apikey>"

Place it next to your __main__.py file.

Otherwise:

You may pass it as a keyword argument.

Example __main__.py:

from threading import Thread

import streamlabsio


def on_twitch_event(event, msg):
    print(f"{event}: {msg.attrs()}")


def register_callbacks(client):
    client.obs.on("streamlabs", on_twitch_event)
    client.obs.on("twitch_account", on_twitch_event)


def main():
    with streamlabsio.connect(token="<apikey>") as client:
        worker = Thread(target=register_callbacks, args=(client,), daemon=True)
        worker.start()

        while cmd := input("<Enter> to exit\n"):
            if not cmd:
                break


if __name__ == "__main__":
    main()

Attributes

For event messages you may inspect the available attributes using attrs().

example:

def on_twitch_event(event, msg):
    print(f"{event}: {msg.attrs()}")

Official Documentation