Update OBS Lower Thirds with Python and Text File
This article explains how to automate lower-third updates in OBS Studio by using a custom Python script to read data from a text file. By utilizing OBS Studio’s native Python scripting interface, you can dynamically update your stream overlays in real-time without manually editing text sources during a live broadcast. This step-by-step guide covers setting up Python in OBS, writing the automation script, and configuring your sources for a seamless live production workflow.
Step 1: Install and Link Python to OBS Studio
OBS Studio includes a scripting engine that supports Python, but you must have a compatible version of Python installed on your computer to use it.
- Download Python: Install Python (typically version 3.10 or 3.11, depending on your OBS version’s compatibility) from the official Python website. Ensure you check the box to “Add Python to PATH” during installation.
- Link Python in OBS: Open OBS Studio, go to Tools in the top menu, and select Scripts.
- Set Path: Navigate to the Python
Settings tab. Click Browse and select the
folder where Python is installed on your system (e.g.,
C:/Users/YourUsername/AppData/Local/Programs/Python/Python310on Windows).
Step 2: Create the Custom Python Script
Create a new Python file named obs_lower_thirds.py using
a text editor or IDE, and paste the following code into it:
import obspython as obs
# Global variables to store user settings
source_name = ""
file_path = ""
update_interval = 2000 # Interval in milliseconds
def update_obs_text():
"""Reads the text file and updates the specified OBS source."""
global source_name
global file_path
if not source_name or not file_path:
return
try:
with open(file_path, "r", encoding="utf-8") as file:
new_text = file.read().strip()
except Exception as e:
print(f"Error reading file: {e}")
return
# Locate the target OBS text source
source = obs.obs_get_source_by_name(source_name)
if source is not None:
settings = obs.obs_data_create()
obs.obs_data_set_string(settings, "text", new_text)
obs.obs_source_update(source, settings)
# Free up memory
obs.obs_data_release(settings)
obs.obs_source_release(source)
def script_properties():
"""Defines the user interface fields in OBS."""
props = obs.obs_properties_create()
obs.obs_properties_add_text(props, "source_name", "Target Text Source", obs.OBS_TEXT_DEFAULT)
obs.obs_properties_add_path(props, "file_path", "Text File Path", obs.OBS_PATH_FILE, "*.txt", None)
return props
def script_update(settings):
"""Triggers whenever settings are changed in OBS."""
global source_name
global file_path
source_name = obs.obs_data_get_string(settings, "source_name")
file_path = obs.obs_data_get_string(settings, "file_path")
# Reset and start the timer
obs.timer_remove(update_obs_text)
if source_name and file_path:
obs.timer_add(update_obs_text, update_interval)Save the file. This script runs a background timer that reads your designated text file every two seconds and pushes any updated text to the designated OBS text source.
Step 3: Set Up Your Sources in OBS Studio
Before running the script, you must prepare the visual elements inside OBS Studio.
- Add a Text Source: In the Sources dock, click the + icon and select Text (GDI+) for Windows or Text (FreeType 2) for macOS/Linux.
- Name the Source: Name the source clearly, such as
Lower_Third_Name. - Design the Graphic: Customize the font, size, color, and background of the text source to match your stream’s aesthetic. Place it in the lower-third region of your canvas.
- Create the Live Text File: Create a blank text file
on your computer named
live_data.txt.
Step 4: Load and Configure the Script in OBS
With your text source and script ready, you can now link them together.
- Open OBS Studio and go to Tools > Scripts.
- Under the Scripts tab, click the + button at the bottom left.
- Locate and select your
obs_lower_thirds.pyscript. - Once loaded, script properties will appear on the right side of the window.
- In the Target Text Source field, type the exact
name of your OBS text source (e.g.,
Lower_Third_Name). - In the Text File Path field, click
Browse and select your
live_data.txtfile. - Click Close.
Now, whenever you open live_data.txt, type a new name or
title, and save the file, the text inside your OBS lower-third graphic
will update automatically within two seconds.