mirror of
https://github.com/onyx-and-iris/streamlabs-socketio-py
synced 2025-02-18 15:55:29 +00:00
79 lines
1.9 KiB
Markdown
79 lines
1.9 KiB
Markdown
[](https://badge.fury.io/py/streamlabsio)
|
|
[](https://github.com/onyx-and-iris/streamlabs-socketio-py/blob/dev/LICENSE)
|
|
[](https://github.com/psf/black)
|
|
[](https://pycqa.github.io/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:
|
|
|
|
```toml
|
|
[streamlabs]
|
|
token = "<apikey>"
|
|
```
|
|
|
|
Place it next to your `__main__.py` file.
|
|
|
|
#### Otherwise:
|
|
|
|
You may pass it as a keyword argument.
|
|
|
|
Example `__main__.py`:
|
|
|
|
```python
|
|
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:
|
|
|
|
```python
|
|
def on_twitch_event(event, msg):
|
|
print(f"{event}: {msg.attrs()}")
|
|
```
|
|
|
|
### Official Documentation
|
|
|
|
- [Streamlabs SocketIO API](https://dev.streamlabs.com/docs/socket-api)
|