Client Service account role mapping

hi,

I want to create a new realm, and a new confidential client and give its service account, realm management roles.

I know how to do that from the UI, is there a rest API to update client service account roles?
can that be configured when creating the client?

specifically I am using python script to create realm, client.

Is there a better way to do realm configurations using code?