Secure Python Credentials with Keyring

To Store the Password

# Store the password

import keyring # pip install keyring

from getpass import getpass


# Prompt user for password

password = getpass(prompt="Enter password:")


# Variable for username

username = "XXXXXXXX"


# Entry used by your own scripts (service name = "system")

keyring.set_password("system", username, password)


To Call the Password

import keyring

username = "XXXXXXXX"

password = keyring.get_password("system", username)


Comments