Using ufw (UncomplicatedFirewall) as an api

Sure, the ufw executable is just a thin wrapper around a python package with the same name. I'm not aware of any documentation, but you can just poke around the source and have a look how everything works. Find the ufw script location using which ufw and the package location by starting the python interpreter, importing the ufw module and asking it for its import path: