Ansible is written in Python, so it's pretty easy to interactive with ansible using python.
There are many reference materials which could be found via Google. We mainly refers to following link:
https://serversforhackers.com/running-ansible-programmatically