In general, iOS does not allow one app to control another app. Apps can provide Siri shortcuts or a URL scheme to allow limited control by other apps, but this has to be specifically supported by the app, and the developer decides what actions can be triggered by other apps.
If the Sonos app provides Siri shortcuts or a URL scheme to control music playback, you can use that, otherwise you're out of luck. It doesn't make a difference whether you use Pythonista or the Shortcuts app to do the automation - both apps only have access to the control endpoints provided by the other app, and nothing more.
It looks like you have a script of your own called ctypes.py in a "temp" folder. Naming your scripts like built-in modules is never a good idea, try renaming it to something like ctypes_tests.py (and restart Pythonista if that doesn't help right away).
Ok, found a working solution in the MapView objc sample:
Need to use a dummy ui.Button and set the Python click handler function as its "action". Then can use the button as the target and sel("invokeAction:") as the action when defining the Objc accessory button.