Programmatically open a System Preference Tab with Python on macOS

I’m hoping this will save someone some research. I’ve used this to open System Preferences > Security > General to point users to change their local passwords:

#!/usr/bin/env python

# References:
# https://macosxautomation.com/system-prefs-links.html
# https://stackoverflow.com/questions/27856351/osx-opening-privacyaccessibility-window-programmatically
# https://www.youtube.com/watch?v=gHz_eXQvh-w

from AppKit import NSWorkspace
from Foundation import NSURL


sys_pref_link = 'x-apple.systempreferences:com.apple.preference.security?General'

# create workspace object
workspace = NSWorkspace.sharedWorkspace()

# Open System Preference
workspace.openURL_(NSURL.URLWithString_(sys_pref_link))