Many programs require passwords from the user.
It's nice when a program can remember the password you give it.
It's nicer when it stores said password safely. However, it's not trivial to do that if you care for cross-platform support.
Or at least it wasn't until Kang Zhang wrote python keyring, a module that abstracts the password storage mechanisms for KDE, GNOME, OSX and windows (and adds a couple of file-based backends just in case).
So, how does it work?
Install it in the usual way. If it's not packaged for your distro/operating system, just use easy_install:
You could also get it from mercurial:
hg clone http://bitbucket.org/kang/python-keyring-lib/
The API is simplicity itself. This is how you save a secret:
import keyring keyring.set_password('keyring_demo','username','thisisabadpassword')
You may get this dialog (or some analog on other platforms):
And here's the proof that it was saved correctly (this is KDE's password manager):
And how do you get the secret back?
import keyring print keyring.get_password('keyring_demo','username')
This is how it runs:
$ python load.py thisisabadpassword
As you can see, the API is as easy as it could possible get. It even chose the KWallet backend automatically because I am in KDE!
Python-keyring is a module that fixes a big problem, so a big thank you to Kang Zhang and Tarek Ziadé (who had the idea)