OBS Studio Web Socket tutorial with examples Python and Javascript

WebSockets are a powerful communication protocol that allows real-time data exchange between a client (such as OBS Studio) and a server.

3 min read
10,530 1 3

Learn how to use the built-in OBS WebSocket 5.x protocol to control scenes, overlays, sources, and streaming state with Python and JavaScript. Updated for OBS Studio 30+.

⚠️ Important: Old tutorials using SetCurrentScene (v4.x) no longer work. OBS Studio now ships with WebSocket v5.x by default (port 4455, JSON-RPC 2.0).

Prerequisites

  • OBS Studio 28+ (WebSocket v5.x is built-in, no plugin needed).
  • Enable the WebSocket server under Tools → WebSocket Server Settings.
  • Client libraries:
    • pip install obsws-python
    • npm install obs-websocket-js

Setting Up OBS WebSocket

  1. Go to Tools → WebSocket Server Settings in OBS.
  2. Enable the server.
  3. Default port is 4455 (WebSocket v5).
  4. Set a secure password & enable authentication.
  5. Click ApplyOK.
Tip: You can test the connection quickly using official test clients.

Python: Change Scene


from obsws_python import obsws, requests

host = "localhost"
port = 4455
password = "your_password"

ws = obsws(host, port, password)
ws.connect()

scene_name = "YourSceneName"
ws.call(requests.SetCurrentProgramScene(scene_name))

ws.disconnect()
      

This script connects, authenticates, and switches the program scene in OBS.

JavaScript: Change Scene


import OBSWebSocket from 'obs-websocket-js';

const obs = new OBSWebSocket();

async function changeScene() {
  try {
    await obs.connect('ws://localhost:4455', 'your_password');
    await obs.call('SetCurrentProgramScene', { sceneName: 'YourSceneName' });
    console.log('Scene changed!');
    await obs.disconnect();
  } catch (err) {
    console.error('OBS WebSocket Error:', err);
  }
}

changeScene();
      

Listening for Events


obs.on('CurrentProgramSceneChanged', data => {
  console.log(`Scene changed to: ${data.sceneName}`);
});

obs.on('StreamStateChanged', state => {
  console.log(`Streaming: ${state.outputActive}`);
});
      

Events allow you to build reactive dashboards and bots that sync with OBS actions.

Advanced Examples

Toggle Source Visibility


await obs.call('SetSceneItemEnabled', {
  sceneName: 'YourSceneName',
  sceneItemId: 3,
  sceneItemEnabled: true
});
      

Get Scene List


const scenes = await obs.call('GetSceneList');
console.log(scenes.scenes);
      

Security Tips

  • Always use a strong password.
  • Restrict to localhost unless remote access is needed.
  • Use WSS + reverse proxy (NGINX) if exposed online.
  • Firewall/IP whitelist where possible.
  • Keep OBS & libraries up to date.

Common Errors

  • Connection refused: Enable server in OBS, check firewall/port 4455.
  • Auth failed: Password mismatch.
  • Invalid request: Use v5 method names (SetCurrentProgramScene not SetCurrentScene).
  • Scene not found: Scene names are case-sensitive.
  • Crashes: Update OBS + client SDK.

Real-World Uses

  • Twitch bots that switch scenes on chat commands.
  • Game event triggers that update overlays in real time.
  • Remote control panels for team productions.
  • Automated production pipelines with scheduled scene changes.

Conclusion

The OBS WebSocket 5.x API is now stable and built-in, making automation easier than ever. With obs-websocket-js and obsws-python, you can build bots, dashboards, and production tools with full control of OBS Studio.

Resources:

Comments (2)

BU
Buckrats April 2, 2024 16:08

Hi - I have tried both the python and javascript versions. I have changed the scene name to match one of my scenes. Both connect to OBS OK, and disconnect cleanly at the end. But the scene does not change, and looking in the OBS log I see 17:01:13.601: [obs-websocket 4.9.1-compat] Response

OB
OBSCountdown August 25, 2025 09:51

The article was updated with the informations related to the latest websocket details

M.
M. Maxim April 3, 2024 13:06

I'll have to update this article because in the latest versions of OBS it seems they have changed the keys for changing the scene, I'm currently having issues myself with the .NET part I want to integrate in this tutorial... Will update as soon as I figure out what's going on with the websocket plugin.

Leave a Comment

Replying to someone. Cancel