Read yaml values from encrypted file with ansible-vault using python

Create an encrypted file secrets.yml with ansible-vault and enter a password:

ansible-vault create secrets.yml
Fill it with following contents:
user: IamUsername
password: IamPassWord
Create a new python file vault.py which will read the password variable from the above encrypted yaml file:
import subprocess
import yaml

def getCreds():
    cmd = "ansible-vault view secrets.yml"
    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (result, error) = process.communicate()

    resultYaml = yaml.load(result)

    user = resultYaml['user']
    password = resultYaml['password']

    return(user, password)

user, password = getCreds()
print (password)
Run the script. This is output:
$ python3.6 vault.py
Vault password: Enter password for encrypted yaml file
IamPassWord