Store and access passwords safely with python’s keyring

Posted in howto , python , simple

old skeleton keysIntegrating a permanent keyring storage system into your python app is now drop dead simple.

From pypi.python.org, “The Python keyring lib provides a easy way to access the system keyring service from python. It can be used in any application that needs safe password storage.”

Install it:

Run easy_install or pip:

$ easy_install keyring
$ pip install keyring

Or install from source:

$ wget http://pypi.python.org/packages/source/k/keyring/keyring-0.2.tar.gz
$ hg clone http://bitbucket.org/kang/python-keyring-lib/

Use it:

Store a password:

$ python
>>> import keyring
>>> keyring.set_password("myapp", "sventek", "krmit")

Now quit (ctrl-d) and start over. You should be able to access the password, like this:

$ python
>>> import keyring
>>> keyring.get_password( "myapp", "sventek" )
'krmit'
>>>

Python keyring lib:

Python keyring library was created as a Google Summer of Code project. The keyring lib supports Windows win32crypto, Mac OS X’s SXKeychain, KDE’s KWallet, Gnome’s keyring, and encrypted or unencrypted password files. When your application wants to store or fetch data from the keyring, it will just work.

This is exactly what I needed — but if easy mode doesn’t suite you and you want/need to make your own backend or specify a specific keyring to use, you can do that by calling set_keyring() or specifying it in a config.

Posted by admica   @   22 December 2009

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Airfare search alternatives to kayak
Next Post
How to disable enemy text chat in Modern Warfare 2 »
Powered by Wordpress   |   Lunated designed by ZenVerse