There is a command personal.listWallets in geth cli to get the account locked/unlocked status such as below:

> personal.listWallets[1]
  accounts: [{
      address: "0x175ec34c2b545a4e2195bfbfe03a82b67e594390",
      url: "keystore:///var/geth/keystore/UTC--2018-07-16T09-18-23.192773724Z--175ec34c2b545a4e2195bfbfe03a82b67e594390"
  status: "Locked",
  url: "keystore:///var/geth/keystore/UTC--2018-07-16T09-18-23.192773724Z--175ec34c2b545a4e2195bfbfe03a82b67e594390"

How can I get the similar account status from python web3 package or send the same command to fetch the information via python web3?

1 Answer 1


Assuming you have been activated personal rpc of your geth, to do this programatically without hardcoding the keystore file directory path in python, do the following:

from web3 import Web3
import eth_keys
from eth_account import account

w3 = Web3(Web3.HTTPProvider(''))
address = '0x...'
password = 'password'

wallets_list = w3.geth.personal.list_wallets()
keyfile_path = (wallets_list[list(i['accounts'][0]['address'] for i in wallets_list).index(address)]['url']).replace("keystore://", "").replace("\\", "/")
keyfile = open(keyfile_path)
keyfile_contents = keyfile.read()
private_key = eth_keys.keys.PrivateKey(account.Account.decrypt(keyfile_contents, password))
public_key = private_key.public_key

private_key_str = str(private_key)
public_key_str = str(public_key)

You can extract other info from this file, too. I just extracted the private key and public key of an address as an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.