This module contains Python interfaces to some command-line programs that come with Mac OS:
osx_keychain
usessecurity
to manipulate keychainsosx_pboard
usespbcopy
andpbpaste
to manipulate the clipboardosx_defaults
usesdefaults
to manipulate preferences
Most of these features are also accessible via PyObjC, which takes some time to import. osx-pyutils
is designed to be used by shell scripts that live for much shorter than that by working with the already-compiled tools. osx-pyutils
can also be used as convenience functions for those who don't want to directly deal with spawning new processes.
This project is currently alpha-quality work and welcomes PRs. Please contribute if you can!
>>> import osx_keychain
>>> d = osx_keychain.Domain('example.com')
>>> d.find_password('interestinglythere')
Traceback (most recent call last):
PasswordNotFoundError: security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
>>> d.add_password('interestinglythere', 'correct horse battery staple')
>>> d.find_password('interestinglythere')
'correct horse battery staple'
>>> d.delete_password('interestinglythere')
>>> d.find_password('interestinglythere')
Traceback (most recent call last):
PasswordNotFoundError: security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
Here's what the result looks like from Keychain Access (before deleting):