Store Password Credentials With Python And GPG

NOTE: This is no longer the way I do stuff. I use the system keychains see [[/posts/storing-local-environmental-variables-securely-in-password-managers-instead-of-plaintext-env-files--20eonil1bcsz][Storing Local Environmental Variables Securely In Password Managers Instead Of Plaintext env Files]] for details

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')