Skip to main content

A Python SDK for OBS Studio WebSocket v5.0 - Fork with MCP server fixes

Project description

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

A Python SDK for OBS Studio WebSocket v5.0

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.9 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: ""
  • timeout: 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 in your user home directory.

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', timeout=3)

# 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. If a successful call is made with the Request client and the response is expected to contain fields then a response object will be returned. You may then access the response fields as class attributes. They will be snake cased.

example:

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

# GetVersion, returns a response object
resp = cl.get_version()
# Access it's field as an attribute
print(f"OBS Version: {resp.obs_version}")


# SetCurrentProgramScene
cl.set_current_program_scene("BRB")

send(param, data=None, raw=False)

If you prefer to work with the JSON data directly the {ReqClient}.send() method accepts an argument, raw. If set to True the raw response data will be returned, instead of a response object.

example:

resp = cl_req.send("GetVersion", raw=True)

print(f"response data: {resp}")

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

  • OBSSDKError: Base error class.
  • OBSSDKTimeoutError: Raised if a timeout occurs during sending/receiving a request or receiving an event
  • OBSSDKRequestError: Raised when a request returns an error code.
    • The following attributes are available:
      • req_name: name of the request.
      • code: request 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

Install hatch and then:

hatch test

Official Documentation

For the full documentation:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obsws_python_mcp-1.8.1.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

obsws_python_mcp-1.8.1-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file obsws_python_mcp-1.8.1.tar.gz.

File metadata

  • Download URL: obsws_python_mcp-1.8.1.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for obsws_python_mcp-1.8.1.tar.gz
Algorithm Hash digest
SHA256 386907b8c0aedfe3fe470e2e604563ccb910dfd054c1cc0836b80bb3d45758e8
MD5 9f758f349c8ad8b16141e6bf50010d91
BLAKE2b-256 a42c5b587df2c9691a9be97473330d4dbea4d51a8faa81261ba4bac09c86e128

See more details on using hashes here.

File details

Details for the file obsws_python_mcp-1.8.1-py3-none-any.whl.

File metadata

File hashes

Hashes for obsws_python_mcp-1.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4ba32dad74c566d736411e82b09ff461c1c7499a5da4f0fef28d012afd4f9ec
MD5 cda34b6190f6f79211c862de46d9c598
BLAKE2b-256 52dc973e91e70d074330a5759608d351527ba43de12e672d24248fcdc3a0db11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page