Have a look at the
Action Chains plugin and see whether it fulfills your needs. It also enables you to write python scripts by using the plugin's module editor to create custom actions. The advantage to this approach to the usual calibre-debug pyhton scripts is that it can read selections from gui and act on them.
For more on using python for calibre development, see the documentation
here.