Using Windows Credential Manager and Keyring With Both R and Python

Why don’t the main R and Python keyring packages, r-lib/keyring and jaraco/keyring, seem to be able to read the same passwords from Windows Credential Manager on Windows 10?

In short: because the R package gives the credentials a name like :service-name:user-name, while the Python package simply uses service-name (or user-name@service-name if there are multiple credentials for the same user).

If you want to store credentials for user mjw for the service local-database, the best way to do that is to open Windows Credential Manager (Start > Credential Manager), click Add a generic credential, and enter:

  • Internet or network address: :local-database:mjw
  • Username: mjw
  • Password: (your password)

Then, to retrieve the password, call keyring::key_get("local-database", "mjw") in R or keyring.get_password(u":local-database:mjw", u"mjw") in Python.

I don’t recommend using either library’s built-in function for saving the credential (keyring::key_set() or keyring.set_password()); it can prevent the other library from being able to read it.

Michael James Williams avatar
About Michael James Williams
Michael James Williams is a data analyst, writer, and editor.