Call ansible playbook/tasks from python script.

I have python script and have to call ansible playbook and tasks in various phases of script execution. What is preferred way to call ansible playbook or task?

I see python API was suggested to use for internal purpose only.
https://docs.ansible.com/ansible/latest/dev_guide/developing_api.html#python-api-example

The other way is to use subprocess. Want to know if subprocess can be used reliably ?

Thanks

I too want to use the Python API. Since Ansible does not guarantee Python API compatibility with older versions, this can become a moving target.

You also have Ansible Runner that's created for this purpose

"A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible."

https://github.com/ansible/ansible-runner

I prefer going python API way.Looks to me there can be stability issues with versions.
for now I will go with subprocess so that I dont have to end up resolving version conflicts down the line.

Thanks for sharing your experience.