Store Your Credentials In Macs Keychain Access With Python

September - 2020

To get credentials from your encrypted store, use this:

This is the original that only works in Python 3

def get_credential(file_path): import subprocess return str(subprocess.run([ '/usr/local/bin/gpg', '--armor', '--decrypt', '-q', file_path ], stdout=subprocess.PIPE).stdout.decode('utf-8')).split("\n")[0]

This should work with both 2 and 3

def get_credentials(file_path): import subprocess return subprocess.check_output([ '/usr/local/bin/gpg', '--decrypt', '-q', file_path ]).decode('utf-8').split("\n")[0]

credential = get_credentials('/Users/alans/credentials/example_credential.asc')