For Python maybe that will help:
OBS doesn't receive hotkey from python script
I can't help you with python, but if you are using a Mac you can control it with AppleScript.
An example would be the following script.
I had an external midi controller flying around here (MPC) that I use for this, but there are also keyboards with function keys.
on runme(message)
tell application "OBS"
activate
end tell
#say item 2 of message
#PAD 1 = 37
if (item 2 of message = 37)
tell application "System Events"
keystroke "s" using control down
end tell
end if
#PAD 2 = 36
if (item 2 of message = 36)
tell application "System Events"
keystroke "b" using control down
end tell
end if
#PAD 3 = 42
if (item 2 of message = 42)
tell application "System Events"
keystroke "p" using control down
end tell
end if
#4 = 54
if (item 2 of message = 54)
tell application "System Events"
keystroke "1" using control down
end tell
end if
#5 = 40
if (item 2 of message = 40)
tell application "System Events"
keystroke "2" using control down
end tell
end if
#6 = 38
#7 = 46
#8 = 44
end runme