I have been searching for hours for the ability to edit / add tags or basically keywords of/to an image via Python. I wanted to change metadata of images so I had to use Piexif library and found it completely great but there is a problem which XPKeywords requires type 'bytes' instead of 'Ascii' for some reason.
I've tried using IPTCInfo library to just edit the keywords but unfortunately didn't go out that good like I wanted to. I've also tried converting the string to bytes via 'b' prefix but still the same problem remains.
I have figured it out myself by using Piexif. For anyone who has the same issue; the solution was that the meta tag was 'XPKeywords' and I had to just encode the keywords string to UCS2 (as stated here https://exiv2.org/tags.html) using 'encode' function with argument 'utf16'. The same goes to comments (meta tag: XPComment). I hope I helped!