I know that this is possible in javascript using the cardano serialization lib, as follows:

function toHex(bytes){
    return Buffer.from(bytes).toString("hex");

function addrToPubKeyHash(bech32Addr) {
  const pkh = Loader.Cardano.BaseAddress.from_address(

  return toHex(pkh.to_bytes());

How would I do the same in python?

1 Answer 1


Check out pycardano. Class Address has a class method from_primitive that can read and decode a bech32 address. Then you can directly read field payment_part, which is the public key hash of the payment credential from the address object. You can find the API documentation here.


>>> from pycardano import Address   
>>> addr = Address.from_primitive("addr_test1vzv89dr7v69enywx0t7sqcyxshcmnlv9q43lhpg7ecfhjjsjcdsza")
>>> addr.payment_part

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.