I used the keyring
library in Python to store a password needed to logon to an external service.
import keyring
keyring.set_password("service_name", "username", "my_password")
password = keyring.get_password("service_name", "my_username")
I no longer need that password saved and would like to delete it. Is there a function to delete credentials set with the keyring
library?
Yes, you can delete keyring credentials with keyring.delete_password
.
keyring.delete_password(service_name, username)
Full example
import keyring
service_name = "name_of_service"
username = "your_username"
keyring.set_password(service_name, username, "my_password")
print(keyring.get_password(service_name, username)) # my_password
keyring.delete_password(service_name, username)
print(keyring.get_password(service_name, username)) # None
If the password does not exist or was already deleted, the library will raise an instance of keyring.errors.PasswordDeleteError
.