I've sent you a link to some changes I made to your blender rigging script... code is not objectively better, just a bit more compact and maybe a little less error prone, just trying to help you save time. I'm amazed and shit scared for you that you're diving this deep into the technical aspect of 3D animation, I have worked with professional riggers whose job it is to write these kind of scripts, it's insane that you're going that far. I hope you're not drowning in these cog wheels. Do you have energy left for non-technical playful creation still? All the best
here's the thing about doing scripting ....................... when the scripting is done, if done properly, it surges the playful into hyperdrive. that is the entire and whole point