Muffinresearch Labs by Stuart Colville

Python: Keychain.py access to the Mac OSX keychain | Comments (4)

Posted in Code on 5th February 2008, 11:53 pm by Stuart

The code in the project has changed somewhat since this post – see the project for more info

keychain.py

I’ve been busy hacking away on a simple little class that makes it really easy to get access to the keychain on mac osx. I’d seen already a way to acces the keychain in this post by Mark Rowe however I wanted to avoid the dependency on objc.

To solve the problem I wrapped the security command which provides fairly comprehensive access to the keychain.

Where this comes in handy is any time that you want to create a Python CLI app that could do with keychain access you can use keychain.py to access credentials stored in the keychain. In addition keychain.py allows keychain settings to be altered and read and you can also create new keychains and keychain items.

Here’s a couple of simple examples of how you can use keychain.py in a script.

Instantiation

>>> import keychain
>>> k=keychain.Keychain();

Create a keychain

>>> k.createkeychain('TopSecret','Shhhssh')
(True, 'Keychain created successfully')

List keychains

>>> k.listkeychains()
{'System': '/Library/Keychains/System.keychain', 'TopSecret': '/Users/muffinman/Library/Keychains/TopSecret.keychain', 'login': '/Users/muffinman/Library/Keychains/login.keychain'}

Set and get a keychain item

>>> k.setgenericpassword('TopSecret', 'muffin','test')
(True, 'Password added to TopSecret.keychain successfully')
>>> k.getgenericpassword('TopSecret', 'muffin')
{'account': 'muffin', 'password': 'test'}

The code is on launchpad.net so if you would like to try it out you can simply checkout the code or download it

As always all feedback and suggestions welcome.

Post Tools

Comments: Add yours

1. On February 7th, 2008 at 5:01 pm Pages tagged "osx" said:

[...] bookmarks tagged osx Python: Keychain.py access to the Mac OSX keychain saved by 30 others     Hanna467 bookmarked on 02/07/08 | [...]

2. On February 14th, 2008 at 9:50 am Cyril Doussin said:

Ok, that’s a really cool icon !

3. On March 11th, 2008 at 7:44 am Larry said:

Very nice. Thank you!

4. On October 15th, 2008 at 8:56 am Banana Rama said:

Thanks a lot!







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Using Loggerhead with mod_wsgi|(0)

Here’s a post I wrote over on the Project Fondue Blog about our use of Loggerhead with mod_wsgi under Apache. Loggerhead is the rather nice branch viewer for bazaar branches as used on Launchpad.net.

If you’re not already subscribed to the Project Fondue blog feed then I can recommend it, as there should be some interesting posts coming out of there in the coming months (yes I’m unashamedly biased!).

Ubuntu: Turn off changing workspace with mouse wheel|(1)

I found the changing with the workspace with the mouse wheel really annoying. To disable it go to System => Preferences => CompizConfig (available if the compizconfig-settings-manager package is installed) and uncheck “Viewport Switcher” which is under the “Desktop” heading.

Photos on Flickr

© Copyright 2004-10 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.668s.