API

Main Function

stream_tool.create_website(use_obs_websockets=False) Website

Create a web server with an index page

Returns:

object – instance of class _website.Website

Return type:

Website

Parameters:

use_obs_websockets (Bool, default False) – If set to true the website creates an OBS websocket managaer to communicate with OBS Websockets

Examples

>>> from stream_tool import create_website
>>> my_site = create_website()

Website Structure Classes

class stream_tool._website.Website(use_obs_websockets=False)

A website and all its information

index_page

The _page.Page object for the index page automatically created by the site

ws

An instance of obsws from package obs-websocket-py. Would be used to create custom OBS controls not provided in builtin_obs_actions and attach to a button function. Use its method call to perform custom actions. The OBS websockets manager created by the site if use_obs_websockets is True.

add_page(name: str, button_color: str = '#3498DB') Page

Add a page on the website

Parameters:
  • name (str) – name of page displayed in tab

  • button_color (str) – the default color for the buttons on the page, default is “#3498db”. follows the same rules as the color attribute of Button class

Returns:

object – instance of class _page.Page

Return type:

Page

Examples

>>> import streamtool
>>> my_site = create_website()
>>> my_page = my_site.add_page('My-Page-Name')
build_and_run(host='127.0.0.1', port=5000, debug=False)

Build website files and routes and run it

This function of the Website class builds the whole website including each page and all its buttons. It creates every html file. It also gives Flask a function to send that html to each user. It also runs the website on the web server.

Examples

>>> import streamtool
>>> my_site = create_website()
>>> my_site.build_and_run()
Parameters:
  • host (str {'127.0.0.1', '0.0.0.0'}) – The host to run the web server on. Defaults to ‘127.0.0.1’ which runs the server locally. Set this to ‘0.0.0.0’ to have the server available externally as well.

  • port (int, default 5000) – The port to run the web server on.

  • debug (bool, default False) – Run flask in debug. Default is off.

class stream_tool._page.Page(website: Website, name, button_color)

A page and all its information

name

The url for the page. Spaces will be replaced with dashes.

Type:

str

url

This is a property that can get the relative url for this page on the website

Type:

str

button_color

the default color for the buttons on the page, default is “#3498db”. follows the same rules as the color attribute of Button class

Type:

str

add_button(name: str, **kwargs) Button

Add a button to a page

Parameters:
  • name (str) – The name of the button

  • **kwargs (dict, optional) – Extra arguments for creating button, refer to Button class docmentation for keyword arguments

Returns:

object – instance of Button class

Return type:

Button

Examples

>>> import streamtool
>>> my_site = create_website()
>>> my_page = my_site.add_page()
>>> my_button = my_page.add_button("button name")
class stream_tool._button.Button(page: Page, name: str, button_function: callable = None, button_function_args: list = None, button_function_kwargs: dict = None, text: str = None, button_link: str = None, color: str = 'default')

A button and all its information

name

The name of the button

Type:

str

text

Text for the button, defaults to the name parameter

Type:

str

color

Color of the button, defaults to “defualt” which is blue. Set it to a valid css color name or a valid rgb hex color.

Type:

str

button_function

Action for button to run on press

Type:

callable

button_function_args

Arguments or single argument to be passed to button_function

Type:

list, Any

button_function_kwargs

Keyword arguments to be passed to button_function

Type:

dict,

A url to a relative page on the site or any page on the web

Type:

str

Websockets Connection & Authentication

Information for connecting to OBS websockets

stream_tool.Websockets_Auth.websocket_host

The ip address of the websockets server to communicate with. Set to ‘127.0.0.1’ by default which is the local machine address.

Type:

str

stream_tool.Websockets_Auth.websocket_port

The port to connect to on the websockets server. Set to 4455 by default which is the OBS default.

Type:

int

stream_tool.Websockets_Auth.websocket_password

The password to connect to the OBS websockets server. Empty by default

Type:

str

OBS Functions

Actions to perform on OBS websockets

Has a set of functions that can be run to tell OBS to do something. These can be attached to buttons to make them happen on a button click.

stream_tool.builtin_obs_actions.change_volume(input_name, amount=6)

Change volume by a dB amount, default is 6 dB,

Use negative dB amount to turn down and a positive dB to turn up

Parameters:
  • input_name (str) – the name of the input to affect

  • amount (int, optional 6) – number of dB to change by, default is 6 dB

stream_tool.builtin_obs_actions.disconnect()

Disconnect the web socket connection

stream_tool.builtin_obs_actions.get_current_program_scene()

Get the current live scene (or program scene if in studio mode)

Returns:

current_scene – The name of the current scene (or current program scene if in studio mode)

Return type:

str

stream_tool.builtin_obs_actions.get_input_settings(input_name)

Get the settings for an input

To be used with set_input_settings which requires the object this returns

Parameters:

input_name (str) – name of the input to get settings for

Returns:

all the settings of the input

Return type:

object

Notes

an input, like a text box, is a type of source. This will get input-specific settings, not the broader source settings like transform and scale For a text source, this will return settings like its font, color, etc

stream_tool.builtin_obs_actions.get_scene_items(scene_name)

Get all names of items in a scene

Parameters:

scene_name (str) – name of the scene to get items from

Returns:

names of items in the scene

Return type:

list

stream_tool.builtin_obs_actions.get_source_transform(scene_name, source_name)

The current transform effects on a source

Used in combination with set_source_transform to change the transform values of a source. Keys in the return dictionary are: positionX, positionY, scaleX, scaleY, cropTop, cropBottom, cropLeft, cropRight, rotation. See: set_source_transform.

Parameters:
  • scene_name (str) – The name of the scene containing the source to get transform

  • source_name (str) – The name of the source to get transform

Returns:

Every aspect that can be transformed as a key and its current value as the value

Return type:

dict

Examples

>>> import stream_tool
>>> source_current_transform =
...     builtin_obs_actions.get_source_transform(
...         "my scene 1", "source I want to change")
>>> source_new_transform = source_current_transform
>>> # Move 100 pixels to the right
>>> source_new_transform["positionX"] += 100
>>> # set bottom crop to 50
>>> source_new_transform["cropBottom"] = 50
>>> builtin_obs_actions.set_source_transform(
...     "my scene 1",
...     "source I want to change",
...     source_new_transform)
stream_tool.builtin_obs_actions.get_text(source_name)

Get the current text of a text source

Parameters:

source_name – the text source to get the current text of

Returns:

text – the current text of the source

Return type:

str

stream_tool.builtin_obs_actions.pause_audio(input_name)

Pause audio playback on an audio input

Parameters:

input_name (str) – The audio input to affect

stream_tool.builtin_obs_actions.play_audio(input_name, file_path=None)

Play audio from a file, if no file is provided it will just play the input

Parameters:
  • input_name (str) – The audio input to affect

  • file_path (str, optional) – The file path of the audio file to play on the system with OBS

stream_tool.builtin_obs_actions.play_pause_audio(input_name)

Toggle play/pause on an audio input

Parameters:

input_name (str) – name of the input to affect

stream_tool.builtin_obs_actions.set_filter_visibility(source_name, filter_name, filter_enabled=True)

Set a source filter visibility

Parameters:
  • source_name (str) – The name of the source to affect

  • filter_name (str) – The name of the filter to affect

  • filter_enabled (bool, optional True) – Set the filter enable (visible) status, default is True (enabled or visible)

stream_tool.builtin_obs_actions.set_input_settings(input_name, input_settings)

Set the settings of an input with a version of the object retrieved from get_input_settings

Parameters:
  • input_name (str) – the name of the input to set settings

  • input_settings (object) – returned from get_input_settings and can then be edited

stream_tool.builtin_obs_actions.set_scene(new_scene)

Set the current scene (or program scene if using studio mode)

Parameters:

new_scene (str) – The name of the scene to set to

stream_tool.builtin_obs_actions.set_source_transform(scene_name, source_name, new_transform)

Set the transform values for a source

The transform should be a dictionary containing any of the following keys with corresponding values positionX, positionY, scaleX, scaleY, cropTop, cropBottom, cropLeft, cropRight, rotation. The current status can be retrieved with get_source_transform.

Parameters:
  • scene_name (str) – the name of the scene containing the source to affect

  • source_name (str) – the name of the source to affect

  • new_transform (dict) – dictionary containing keys of property to change and the value to set it to. Can get the current values with get_source_transform or just set the desired keys

Examples

>>> import stream_tool
>>> transform = {"scaleX": 2,
...              "scaleY": 3}
>>> set_source_transform("my scene 1", "source I want to change", transform)

This is an alternate example using get_source_transform to update relative to current values

>>> import stream_tool
>>> source_current_transform = builtin_obs_actions.get_source_transform("my scene 1", "source I want to change")
>>> source_new_transform = source_current_transform
>>> # Move 100 pixels to the right
>>> source_new_transform["positionX"] += 100
>>> builtin_obs_actions.set_source_transform("my scene 1", "source I want to change", source_new_transform)
stream_tool.builtin_obs_actions.set_source_visibility(scene_name, source_name, source_visible=True)

Set a source visibility

Parameters:
  • scene_name (str) – The name of the scene containing the source to affect

  • source_name (str) – The name of the source to affect

  • source_visible (bool, optional True) – Set to source enable (visible) status, default is True (enabled or visible)

stream_tool.builtin_obs_actions.set_text(source_name, new_text)

Set the text of a text source

Parameters:
  • source_name (str) – The name of text source to change

  • new_text (srt) – The text to set the source to

stream_tool.builtin_obs_actions.stop_audio(input_name)

Stop audio playback on an audio input

Parameters:

input_name (str) – The audio input to affect

stream_tool.builtin_obs_actions.toggle_input_mute(input_name)

Toggle the mute status of an input

Parameters:

input_name (str) – the input to affect

stream_tool.builtin_obs_actions.transition_to_scene(scene_name, transition_name)

Transition to a scene in studio mode

This puts a scene in preview and then runs a transition to go to that scene.

Parameters:
  • scene_name (str) – The name of the scene to transition to

  • transition_name (str) – The name of the transition to use

Exceptions

All the custom exceptions that can be raised

exception stream_tool.exceptions.ButtonNameSyntaxError

Button name includes invalid syntax for a button name

exception stream_tool.exceptions.DuplicateButtonNameError

More than one of the same button name created

exception stream_tool.exceptions.DuplicateError

More than one of something in the website

exception stream_tool.exceptions.DuplicatePageNameError

More than one of the same page name created

exception stream_tool.exceptions.DuplicateWebsiteError

More than one website created

exception stream_tool.exceptions.InvalidColorValueError

Not a valid CSS color name or not valid css color hex number