https://gitlab.com/kicad/libraries/kicad-library-utils Might have some good information to see how libraries can be modified programatically