A Python SDK for OBS Studio WebSocket v5.0
Go to file
onyx-and-iris 92e2c29bd6 enum.py renamed to subs.py.
No changes to file contents.

relative import changed in __init__.py
2022-12-05 16:39:33 +00:00
examples fix docstring, add docstring. 2022-10-26 12:13:32 +01:00
obsws_python enum.py renamed to subs.py. 2022-12-05 16:39:33 +00:00
tests namechange ops 2022-09-04 14:20:40 +03:00
.gitignore add version.py 2022-10-28 16:57:06 +01:00
LICENSE initial commit including request calls to obswebsocket 2022-06-05 14:40:55 +03:00
pyproject.toml add version.py 2022-10-28 16:57:06 +01:00
README.md add defaultkwarg section to readme. 2022-11-17 11:32:03 +00:00
setup.py add version.py 2022-10-28 16:57:06 +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

  • OBS Studio
  • OBS Websocket v5 Plugin
    • With the release of OBS Studio version 28, Websocket plugin is included by default. But it should be manually installed for earlier versions of OBS.
  • Python 3.10 or greater

How to install using pip

pip install obsws-python

How to Use

By default the clients connect with parameters:

  • host: "localhost"
  • port: 4455
  • password: None

You may override these parameters by storing them in a toml config file or passing them as keyword arguments.

Order of precedence: keyword arguments then config file then default values.

config file

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:

Example __main__.py:

import obsws_python 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:

# load conn info from config.toml
cl = obs.ReqClient()

# GetVersion
resp = cl.get_version()

# SetCurrentProgramScene
cl.set_current_program_scene("BRB")

For a full list of requests refer to Requests

Events

When registering a callback function use the name of the expected API event in snake case form, prepended with "on_".

example:

# load conn info from config.toml
cl = obs.EventClient()

def on_scene_created(data):
    ...

# SceneCreated
cl.callback.register(on_scene_created)

def on_input_mute_state_changed(data):
    ...

# InputMuteStateChanged
cl.callback.register(on_input_mute_state_changed)

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

# You may also deregister a callback
cl.callback.deregister(on_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 on_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

Logging

If you want to see the raw messages simply set log level to DEBUG

example:

import obsws_python as obs
import logging


logging.basicConfig(level=logging.DEBUG)
...

Tests

First install development dependencies:

pip install -e .['dev']

To run all tests:

pytest -v

Official Documentation

For the full documentation: