Python Command Line Tutorial
First, I'll show how kwallet can be used from the Python command line to read and write a password:
$ python
Tutorial as a Python module
Usually you want to create some simple functions for wrapping around kwallet methods. The following Python module can open a wallet, receive and set a password:
#!/usr/bin/python from PyKDE4.kdeui import KWallet from PyQt4 import QtGui def open_wallet(): app = QtGui.QApplication([]) wallet = KWallet.Wallet.openWallet( KWallet.Wallet.LocalWallet(), 0) if not wallet.hasFolder('kwallet_example'): wallet.createFolder('kwallet_example') wallet.setFolder('kwallet_example') return wallet def get_password(wallet): key, qstr_password = wallet.readPassword('mykey')
It can be used as follows:
$ python >>> import kwallet_example >>> wallet = kwallet_example.open_wallet() >>> kwallet_example.set_password(wallet, 'mypass') >>> kwallet_example.get_password(wallet)
hcs42 source share