A Python SDK for OBS Studio WebSocket v5.0
Go to file
Adem 35b7c16b6b
update readme
ReqClient  object initialization  should be done as follows
```python
from obsstudio_sdk import reqs
cl = reqs.ReqClient(host, port, password)
```
2022-08-26 13:17:29 +03:00
examples update version in hotkey example. 2022-07-27 23:54:46 +01:00
obsstudio_sdk More request tests added. 2022-07-30 16:37:07 +01:00
tests remove redundant imports in tests 2022-07-30 17:18:01 +01:00
.gitignore edited gitignore and setup.py 2022-07-29 16:34:43 +03:00
LICENSE initial commit including request calls to obswebsocket 2022-06-05 14:40:55 +03:00
README.md update readme 2022-08-26 13:17:29 +03:00
setup.py add pypi badge to readme 2022-08-05 13:30:12 +01:00

PyPI version License: GPL v3 Code style: black Imports: isort

A Python SDK for OBS Studio WebSocket v5.0

This is a wrapper around OBS Websocket. Not all endpoints in the official documentation are implemented.

Requirements

How to install using pip

pip install obsstudio-sdk

How to Use

Load connection info from toml config. A valid config.toml might look like this:

[connection]
host = "localhost"
port = 4455
password = "mystrongpass"

It should be placed next to your __main__.py file.

Otherwise:

Import and start using, keyword arguments are as follows:

  • host: obs websocket server
  • port: port to access server
  • password: obs websocket server password

Example __main__.py:

from obsstudio_sdk import reqs as obs

# pass conn info if not in config.toml
cl = obs.ReqClient(host='localhost', port=4455, password='mystrongpass')

# Toggle the mute state of your Mic input
cl.toggle_input_mute('Mic/Aux')

Requests

Method names for requests match the API calls but snake cased.

example:

from obsstudio_sdk import reqs as obs
cl = obs.ReqClient(host='localhost', port=4455, password='mystrongpass')


# GetVersion
resp = cl.get_version()

# SetCurrentProgramScene
cl.set_current_program_scene()

For a full list of requests refer to Requests

Events

When registering a function callback use the name of the expected API event in snake case form.

example:

cl = EventClient()

def scene_created(data):
    ...

# SceneCreated
cl.callback.register(scene_created)

def input_mute_state_changed(data):
    ...

# InputMuteStateChanged
cl.callback.register(input_mute_state_changed)

# returns a list of currently registered events
print(cl.callback.get())

# You may also deregister a callback
cl.callback.deregister(input_mute_state_changed)

register(fns) and deregister(fns) accept both single functions and lists of functions.

For a full list of events refer to Events

Attributes

For both request responses and event data you may inspect the available attributes using attrs().

example:

resp = cl.get_version()
print(resp.attrs())

def scene_created(data):
    print(data.attrs())

Errors

If a request fails an OBSSDKError will be raised with a status code.

For a full list of status codes refer to Codes

Tests

First install development dependencies:

pip install -e .['dev']

To run all tests:

pytest -v

Official Documentation

For the full documentation: