Python utility that wraps a couple Carbon functions (TISCreateInputSourceList and TISSelectInputSource) to programmatically switch input languages on macOS.
Requires the PyObjC package.
from pyinputlanguage import macSwitchInputLanguage
macSwitchInputLanguage("com.apple.inputmethod.Kotoeri.Japanese")