1 Commits

Author SHA1 Message Date
f70583d7ca Merge pull request #58 from onyx-and-iris/add-v5.4-v5.5-reqs
add v5.4, v5.5 methods
2025-07-01 09:20:00 +01:00
7 changed files with 1792 additions and 2847 deletions

181
.gitignore vendored
View File

@@ -1,14 +1,8 @@
# Generated by ignr: github.com/onyx-and-iris/ignr
## Python ##
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[codz] *.py[cod]
*$py.class *$py.class
# C extensions
*.so
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
@@ -23,22 +17,11 @@ parts/
sdist/ sdist/
var/ var/
wheels/ wheels/
share/python-wheels/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
MANIFEST MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports # Unit test / coverage reports
htmlcov/ htmlcov/
.tox/ .tox/
@@ -49,169 +32,27 @@ htmlcov/
nosetests.xml nosetests.xml
coverage.xml coverage.xml
*.cover *.cover
*.py.cover
.hypothesis/ .hypothesis/
.pytest_cache/ .pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
#poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
#pdm.lock
#pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
#pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments # Environments
.env .env
.envrc
.venv .venv
env/ env/
venv/ venv/
ENV/ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
.hatch
# Spyder project settings # pyenv
.spyderproject # For a library or package, you might want to ignore these files since the code is
.spyproject # intended to run in multiple environments; otherwise, check them in:
.python-version
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
.vscode/
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Cursor
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
# refer to https://docs.cursor.com/context/ignore-files
.cursorignore
.cursorindexingignore
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# End of ignr
tools/
# Test/config
test-*.py test-*.py
config.toml config.toml
obsws.log
.vscode/

View File

@@ -1,23 +0,0 @@
version: '3'
tasks:
default:
desc: Generate ReqClient methods from the API spec
deps: [generate]
generate:
desc: Generate ReqClient methods from the API spec
deps: [pull-protocol-json]
cmds:
- python tools/generate.py
- hatch run style:fmt
internal: true
pull-protocol-json:
desc: Pull the latest API spec from the obs-websocket repository
preconditions:
- sh: '[ ! -f tools/protocol.json ] || [ "$(find tools/protocol.json -mmin +1440)" ]'
msg: 'The protocol.json file is up to date (last modified less than 24 hours ago).'
cmds:
- curl -sSfL -o tools/protocol.json "https://raw.githubusercontent.com/obsproject/obs-websocket/refs/heads/master/docs/generated/protocol.json"
internal: true

File diff suppressed because it is too large Load Diff

View File

@@ -9,8 +9,13 @@ description = "A Python SDK for OBS Studio WebSocket v5.0"
readme = "README.md" readme = "README.md"
license = { text = "GPL-3.0-only" } license = { text = "GPL-3.0-only" }
requires-python = ">=3.9" requires-python = ">=3.9"
authors = [{ name = "Adem Atikturk", email = "aatikturk@gmail.com" }] authors = [
dependencies = ["tomli >= 2.0.1;python_version < '3.11'", "websocket-client"] { name = "Adem Atikturk", email = "aatikturk@gmail.com" },
]
dependencies = [
"tomli >= 2.0.1;python_version < '3.11'",
"websocket-client",
]
[project.urls] [project.urls]
Homepage = "https://github.com/aatikturk/obsws-python" Homepage = "https://github.com/aatikturk/obsws-python"
@@ -19,10 +24,9 @@ Homepage = "https://github.com/aatikturk/obsws-python"
path = "obsws_python/version.py" path = "obsws_python/version.py"
[tool.hatch.build.targets.sdist] [tool.hatch.build.targets.sdist]
include = ["/obsws_python"] include = [
"/obsws_python",
[tool.hatch.env] ]
requires = ["hatch-dotenv"]
[tool.hatch.envs.default] [tool.hatch.envs.default]
dependencies = ["pre-commit"] dependencies = ["pre-commit"]
@@ -38,11 +42,6 @@ scene_rotate = "python {root}\\examples\\scene_rotate\\."
[tool.hatch.envs.hatch-test] [tool.hatch.envs.hatch-test]
randomize = true randomize = true
env-include = ["OBSWS_TEST_*"]
[tool.hatch.env.collectors.dotenv.hatch-test]
env-files = [".env"]
fail-on-missing = true
[tool.hatch.envs.hatch-test.scripts] [tool.hatch.envs.hatch-test.scripts]
run = "pytest{env:HATCH_TEST_ARGS:} {args}" run = "pytest{env:HATCH_TEST_ARGS:} {args}"
@@ -52,11 +51,20 @@ python = ["313", "312", "311", "310", "39"]
[tool.hatch.envs.style] [tool.hatch.envs.style]
detached = true detached = true
dependencies = ["black", "isort"] dependencies = [
"black",
"isort",
]
[tool.hatch.envs.style.scripts] [tool.hatch.envs.style.scripts]
check = ["black --check --diff .", "isort --check-only --diff ."] check = [
fmt = ["isort .", "black ."] "black --check --diff .",
"isort --check-only --diff .",
]
fmt = [
"isort .",
"black .",
]
[tool.black] [tool.black]
line-length = 88 line-length = 88
@@ -74,4 +82,4 @@ extend-exclude = '''
[tool.isort] [tool.isort]
profile = "black" profile = "black"
skip = [".gitignore", ".dockerignore"] skip = [".gitignore", ".dockerignore"]
skip_glob = [".git/*", ".hatch/*", ".pytest_cache/*"] skip_glob = [".git/*", ".hatch/*", ".pytest_cache/*"]

View File

@@ -1,25 +1,19 @@
import os
import obsws_python as obs import obsws_python as obs
req_cl = obs.ReqClient( req_cl = obs.ReqClient()
host=os.getenv("OBSWS_TEST_HOST", "localhost"),
port=int(os.getenv("OBSWS_TEST_PORT", 4455)),
password=os.getenv("OBSWS_TEST_PASSWORD", ""),
)
def setup_module(): def setup_module():
req_cl.create_scene(scene_name="START_TEST") req_cl.create_scene("START_TEST")
req_cl.create_scene(scene_name="BRB_TEST") req_cl.create_scene("BRB_TEST")
req_cl.create_scene(scene_name="END_TEST") req_cl.create_scene("END_TEST")
def teardown_module(): def teardown_module():
req_cl.remove_scene(scene_name="START_TEST") req_cl.remove_scene("START_TEST")
req_cl.remove_scene(scene_name="BRB_TEST") req_cl.remove_scene("BRB_TEST")
req_cl.remove_scene(scene_name="END_TEST") req_cl.remove_scene("END_TEST")
resp = req_cl.get_studio_mode_enabled() resp = req_cl.get_studio_mode_enabled()
if resp.studio_mode_enabled: if resp.studio_mode_enabled:
req_cl.set_studio_mode_enabled(studio_mode_enabled=False) req_cl.set_studio_mode_enabled(False)
req_cl.base_client.ws.close() req_cl.base_client.ws.close()

View File

@@ -1,5 +1,3 @@
import os
import pytest import pytest
import obsws_python as obsws import obsws_python as obsws
@@ -10,11 +8,7 @@ class TestErrors:
__test__ = True __test__ = True
def test_it_raises_an_obssdk_error_on_incorrect_password(self): def test_it_raises_an_obssdk_error_on_incorrect_password(self):
bad_conn = { bad_conn = {"host": "localhost", "port": 4455, "password": "incorrectpassword"}
"host": os.getenv("OBSWS_TEST_HOST", "localhost"),
"port": int(os.getenv("OBSWS_TEST_PORT", 4455)),
"password": "incorrectpassword",
}
with pytest.raises( with pytest.raises(
obsws.error.OBSSDKError, obsws.error.OBSSDKError,
match="failed to identify client with the server, please check connection settings", match="failed to identify client with the server, please check connection settings",
@@ -22,11 +16,7 @@ class TestErrors:
obsws.ReqClient(**bad_conn) obsws.ReqClient(**bad_conn)
def test_it_raises_an_obssdk_error_if_auth_enabled_but_no_password_provided(self): def test_it_raises_an_obssdk_error_if_auth_enabled_but_no_password_provided(self):
bad_conn = { bad_conn = {"host": "localhost", "port": 4455, "password": ""}
"host": os.getenv("OBSWS_TEST_HOST", "localhost"),
"port": int(os.getenv("OBSWS_TEST_PORT", 4455)),
"password": "",
}
with pytest.raises( with pytest.raises(
obsws.error.OBSSDKError, obsws.error.OBSSDKError,
match="authentication enabled but no password provided", match="authentication enabled but no password provided",
@@ -38,7 +28,7 @@ class TestErrors:
obsws.error.OBSSDKRequestError, obsws.error.OBSSDKRequestError,
match="Request SetCurrentProgramScene returned code 600. With message: No source was found by the name of `invalid`.", match="Request SetCurrentProgramScene returned code 600. With message: No source was found by the name of `invalid`.",
) as exc_info: ) as exc_info:
req_cl.set_current_program_scene(scene_name="invalid") req_cl.set_current_program_scene("invalid")
e = exc_info.value e = exc_info.value
assert e.req_name == "SetCurrentProgramScene" assert e.req_name == "SetCurrentProgramScene"

View File

@@ -11,8 +11,8 @@ class TestRequests:
assert hasattr(resp, "obs_version") assert hasattr(resp, "obs_version")
assert hasattr(resp, "obs_web_socket_version") assert hasattr(resp, "obs_web_socket_version")
def test_get_hotkey_list(self): def test_get_hot_key_list(self):
resp = req_cl.get_hotkey_list() resp = req_cl.get_hot_key_list()
assert resp.hotkeys assert resp.hotkeys
assert any(x.startswith("OBSBasic.") for x in resp.hotkeys) assert any(x.startswith("OBSBasic.") for x in resp.hotkeys)
@@ -24,20 +24,16 @@ class TestRequests:
], ],
) )
def test_persistent_data(self, name, data): def test_persistent_data(self, name, data):
req_cl.set_persistent_data( req_cl.set_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name, data)
realm="OBS_WEBSOCKET_DATA_REALM_PROFILE", slot_name=name, slot_value=data resp = req_cl.get_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name)
)
resp = req_cl.get_persistent_data(
realm="OBS_WEBSOCKET_DATA_REALM_PROFILE", slot_name=name
)
assert resp.slot_value == data assert resp.slot_value == data
@pytest.mark.skip(reason="possible bug in obs-websocket, needs checking") @pytest.mark.skip(reason="possible bug in obs-websocket, needs checking")
def test_profile_list(self): def test_profile_list(self):
req_cl.create_profile(profile_name="test") req_cl.create_profile("test")
resp = req_cl.get_profile_list() resp = req_cl.get_profile_list()
assert "test" in resp.profiles assert "test" in resp.profiles
req_cl.remove_profile(profile_name="test") req_cl.remove_profile("test")
resp = req_cl.get_profile_list() resp = req_cl.get_profile_list()
assert "test" not in resp.profiles assert "test" not in resp.profiles
@@ -47,8 +43,8 @@ class TestRequests:
"key": "live_myvery_secretkey", "key": "live_myvery_secretkey",
} }
req_cl.set_stream_service_settings( req_cl.set_stream_service_settings(
stream_service_type="rtmp_common", "rtmp_common",
stream_service_settings=settings, settings,
) )
resp = req_cl.get_stream_service_settings() resp = req_cl.get_stream_service_settings()
assert resp.stream_service_type == "rtmp_common" assert resp.stream_service_type == "rtmp_common"
@@ -66,17 +62,13 @@ class TestRequests:
], ],
) )
def test_current_program_scene(self, scene): def test_current_program_scene(self, scene):
req_cl.set_current_program_scene(scene_name=scene) req_cl.set_current_program_scene(scene)
resp = req_cl.get_current_program_scene() resp = req_cl.get_current_program_scene()
assert resp.current_program_scene_name == scene assert resp.current_program_scene_name == scene
def test_input_list(self): def test_input_list(self):
req_cl.create_input( req_cl.create_input(
scene_name="START_TEST", "START_TEST", "test", "color_source_v3", {"color": 4294945535}, True
input_name="test",
input_kind="color_source_v3",
input_settings={"color": 4294945535},
scene_item_enabled=True,
) )
resp = req_cl.get_input_list() resp = req_cl.get_input_list()
for input_item in resp.inputs: for input_item in resp.inputs:
@@ -88,18 +80,14 @@ class TestRequests:
# This else block is executed if the for loop completes without finding the input_item with inputName "test" # This else block is executed if the for loop completes without finding the input_item with inputName "test"
raise AssertionError("Input with inputName 'test' not found") raise AssertionError("Input with inputName 'test' not found")
resp = req_cl.get_input_settings(input_name="test") resp = req_cl.get_input_settings("test")
assert resp.input_kind == "color_source_v3" assert resp.input_kind == "color_source_v3"
assert resp.input_settings == {"color": 4294945535} assert resp.input_settings == {"color": 4294945535}
req_cl.remove_input(input_name="test") req_cl.remove_input("test")
def test_source_filter(self): def test_source_filter(self):
req_cl.create_source_filter( req_cl.create_source_filter("START_TEST", "test", "color_key_filter_v2")
source_name="START_TEST", resp = req_cl.get_source_filter_list("START_TEST")
filter_name="test",
filter_kind="color_key_filter_v2",
)
resp = req_cl.get_source_filter_list(source_name="START_TEST")
assert resp.filters == [ assert resp.filters == [
{ {
"filterEnabled": True, "filterEnabled": True,
@@ -109,7 +97,7 @@ class TestRequests:
"filterSettings": {}, "filterSettings": {},
} }
] ]
req_cl.remove_source_filter(source_name="START_TEST", filter_name="test") req_cl.remove_source_filter("START_TEST", "test")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"state", "state",
@@ -119,6 +107,6 @@ class TestRequests:
], ],
) )
def test_studio_mode_enabled(self, state): def test_studio_mode_enabled(self, state):
req_cl.set_studio_mode_enabled(studio_mode_enabled=state) req_cl.set_studio_mode_enabled(state)
resp = req_cl.get_studio_mode_enabled() resp = req_cl.get_studio_mode_enabled()
assert resp.studio_mode_enabled == state assert resp.studio_mode_enabled == state