This question was addressed nicely by alambre using python (as requested). @chris proposed an Animation nodes solution but didn't get the opportunity to elaborate.
I'm curious to know what an animation nodes solution would look like to the same problem. I'd hope to try both solutions and weigh up the pros and cons in the context of my own production workflow. Thanks for reading my question and for your time.