Create a profile with a .yaml from a Python script

Hello to everyone.

sudo lxc profile edit routed_192.168.2.21 < net_192.168.2.21.yaml

This works fine and set ups fine the routed profile.

How can i do the same from a Python script ?

I used os.sytem and subprocess but didn’t work well.

Can someone please help me with this ?

I can’t figure out from the docs how should i construct the python dictionary which is the .yaml in fact.

Thanks in advance for the help.
Once again grateful for all the guys answering the questions and solving the problems.