Get real time Twitch/Youtube events through Streamlabs Socket API
Go to file
2023-08-19 21:41:23 +01:00
examples/debug add debug example 2023-06-28 02:47:23 +01:00
streamlabsio raw property added. 2023-08-19 21:38:32 +01:00
__main__.py msg renamed to data 2023-06-28 02:48:12 +01:00
.gitignore 1.0.0 section added to changelog 2023-06-28 03:36:38 +01:00
CHANGELOG.md 1.0.0 section added to changelog 2023-06-28 03:36:38 +01:00
LICENSE Initial commit 2022-11-13 08:17:36 +00:00
poetry.lock debug script added to pyproject.toml 2023-06-28 02:49:15 +01:00
pyproject.toml minor version bump 2023-08-19 21:41:23 +01:00
README.md add poetry badge to readme 2023-08-19 21:41:04 +01:00
scripts.py fixes bug subprocess not inheriting variables 2023-08-19 21:40:57 +01:00

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

A Python client for Streamlabs Socket API

For an outline of past/future changes refer to: CHANGELOG

Requirements

  • A Streamlabs Socket API key.

    • You can acquire this by logging into your Streamlabs.com dashboard then Settings->Api Settings->API Tokens
  • Python 3.8 or greater

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:

import streamlabsio


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


def main():
    with streamlabsio.connect(token="<apikey>") as client:
        client.obs.on("streamlabs", on_twitch_event)
        client.obs.on("twitch_account", on_twitch_event)

        # run for 30 seconds then disconnect client from server
        client.sio.sleep(30)


if __name__ == "__main__":
    main()

note

From the SocketIO docs, client.sio.wait() may be used if your application has nothing to do in the main thread.

Client class

streamlabsio.connect(token="<apikey>", raw=False)

The following keyword arguments may be passed:

  • token: str Streamlabs SocketIO api token.
  • raw: boolean=False Receive raw data messages as json objects.

The following attribute is available:

  • raw: boolean Toggle raw mode at runtime.

Attributes

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

example:

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

Errors

  • SteamlabsSIOConnectionError: Exception raised when connection errors occur

Logging

To view raw incoming event data set logging level to DEBUG. Check debug example.

Official Documentation