<p>By last part I assume you mean just the <code>bech32.sh</code>. If so, you can use the below :</p>
<pre><code>encodedstr=bech32.bech32_encode(&quot;prefix&quot;,bech32.convertbits(bytes.fromhex(hexstr), 8, 5))
</code></pre>

CC BY-SA 4.0
2022-07-06T11:25:38.747Z
perfect. TY mate.
LegionOfBrad
CC BY-SA 4.0
2022-07-06T11:02:24.077Z
2022-07-06T11:02:24.077Z
RdLrT
<p>We currently use a python script to get fingerprints from assetName and policy id. However we are resorting to using the cardano bech32 binary for the final part of the process.</p>
<pre><code>from hashlib import blake2b
from subprocess import check_output
import binascii
import bech32
import sys

policyId = '60a75d4bfee53ebe583679faed1fba8a8921abfd685dbc76e313032a'
tokenId = '416433763173446576696c7331313739'
binary_asset = binascii.unhexlify(policyId + tokenId)
output = blake2b(binary_asset, digest_size=20).hexdigest()
output = check_output([f&quot;/home/bech32bin/bech32.sh&quot;, str(output)]).decode(sys.stdout.encoding).strip()

print(output)

### output is asset1rgafp0kmehn9ws6g9224fyjd550wakdhlupk0k (correct)
</code></pre>
<p>Where the contents of bech32.sh are:</p>
<pre><code>/home/bech32bin/bech32 asset &lt;&lt;&lt; $1
</code></pre>
<p>This utilises the bech32 binary for the final stage of the process detailed in pseudocode here <a href="https://cips.cardano.org/cips/cip14/" rel="nofollow noreferrer">https://cips.cardano.org/cips/cip14/</a></p>
<p>Does anyone have an idea for a pythonic method of doing the last part. Without having to call a subprocess (which is slow, especially when looping through on potentially thousands of nfts) I assume with pythons inbuilt bech32 lib but have been unable to replicate.</p>

<python><bech32>
Encoding / Decoding Fingerprint with Python
# Encoding / Decoding Fingerprint with Python

(Asked by: username_0 on 2022-07-06)

We currently use a python script to get fingerprints from assetName and policy id. However we are resorting to using the cardano bech32 binary for the final part of the process.
from hashlib import blake2b
from subprocess import check_output
import binascii
import bech32
import sys

policyId = '60a75d4bfee53ebe583679faed1fba8a8921abfd685dbc76e313032a'
tokenId = '416433763173446576696c7331313739'
binary_asset = binascii.unhexlify(policyId + tokenId)
output = blake2b(binary_asset, digest_size=20).hexdigest()
output = check_output([f"/home/bech32bin/bech32.sh", str(output)]).decode(sys.stdout.encoding).strip()

print(output)

### output is asset1rgafp0kmehn9ws6g9224fyjd550wakdhlupk0k (correct)

Where the contents of bech32.sh are:
/home/bech32bin/bech32 asset <<< $1

This utilises the bech32 binary for the final stage of the process detailed in pseudocode here https://cips.cardano.org/cips/cip14/
Does anyone have an idea for a pythonic method of doing the last part. Without having to call a subprocess (which is slow, especially when looping through on potentially thousands of nfts) I assume with pythons inbuilt bech32 lib but have been unable to replicate.

**Tags:** python, bech32

---

## 1 answers

### Answer by username_1 on 2022-07-06. Score: 4 | Accepted answer

By last part I assume you mean just the bech32.sh. If so, you can use the below :
encodedstr=bech32.bech32_encode("prefix",bech32.convertbits(bytes.fromhex(hexstr), 8, 5))

> **Comments:**
> **username_0**: perfect. TY mate.  

---

