Get real time Twitch/Youtube events through Streamlabs Socket API
Go to file
dependabot[bot] 3f5944bdcc
Bump urllib3 from 2.0.7 to 2.2.2
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.0.7 to 2.2.2.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/2.0.7...2.2.2)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-06 15:13:36 +00:00
examples/debug add debug example 2023-06-28 02:47:23 +01:00
streamlabsio base error class added 2023-08-19 21:59:14 +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 Bump urllib3 from 2.0.7 to 2.2.2 2024-07-06 15:13:36 +00:00
pyproject.toml --- 2024-05-22 09:19:44 +00:00
README.md base error class added 2023-08-19 21:59:14 +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

  • SteamlabsSIOError: Base StreamlabsSIO error class
  • SteamlabsSIOConnectionError: Exception raised when connection errors occur

Logging

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

Official Documentation