Playbook datastructure when using the Python API

Hello,

In order to harmonize several in-house operations, I wrote some self-contained Python command line tools built upon the Ansible core.
As it is not desirable to be dependent on several external files, my code embeds both the the host file and the tasks to execute.
For the latter I used as starting point the example of online manual. However, more complex constructs are missing: e.g. I do not know
how to express conditionals statements like “when” and “block”. Generally speaking, is it possible to have a better understanding of the
playbook datastructure in the Python realm ?

Thanks in advance