Getting Unable to find an inventory file error programtically in Python

Hi I am working with Ansible API but I run into problem with the Playbook module.

I’ve done some reading in https://github.com/oriolrius/programming-ansible-basics/blob/master/test_playbook.py and also looked through help(Inventory). Despite Inventory object has methods like is_file.

But it seems like PlayBook is expecting file instead?

Literally my code is like what’s in ansible code:

self._playbook = ansible_playbook.PlayBook(
playbook=pb_path,
inventory=self._inventory,
stats=stats,
runner_callbacks=runner_cb,
callbacks=playbook_cb,
**other_options
)

Thoughts?

Thanks.