Most Electrum commands are available not only using the command-line, but also in the GUI Python console.

The results are Python objects, even though they are sometimes rendered as JSON for clarity.

Let us call listunspent(), to see the list of unspent outputs in the wallet:



>> listunspent()


[

    {

        "address": "SimqhPqM7xkjrjExYFoMsRUnjam41J5ahx",

        "coinbase": false,

        "height": 664026,

        "prevout_hash": "7c2e07cd3e776e6e06607852e4ae4ad5bbca0c70628e476a637405ab77fc7b90",

        "prevout_n": 1,

        "value": "4.99"

    }

]




Note that the result is rendered as JSON. However, if we save it to a Python variable, it is rendered as a Python object:



>> u = listunspent()

>> u

[{'prevout_n': 1, 'coinbase': False, 'value': '4.99', 'address': 'SimqhPqM7xkjrjExYFoMsRUnjam41J5ahx', 'prevout_hash': '7c2e07cd3e776e6e06607852e4ae4ad5bbca0c70628e476a637405ab77fc7b90', 'height': 664026}]

>> 



This makes it possible to combine Electrum commands with Python. For example, let us pick only the addresses in the previous result:



>> map(lambda x:x.get('address'), listunspent())
[
 "SimqhPqM7xkjrjExYFoMsRUnjam41J5ahx",
 "SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx"
]



Here we combine two commands, listunspent and dumpprivkeys, in order to dump the private keys of all adresses that have unspent outputs:



>> dumpprivkeys( map(lambda x:x.get('address'), listunspent()) )
{
 "SimqhPqM7xkjrjExYFoMsRUnjam41J5ahx": "***************************************************",
 "SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx": "***************************************************"
}



Note that dumpprivkey will ask for your password if your wallet is encrypted. The GUI methods can be accessed through the gui variable. For example, you can display a QR code from a string using gui.show_qrcode. Example:



gui.show_qrcode(dumpprivkey(listunspent()[0]['address']))