<p>There are at least two I'm aware of: <a href="https://github.com/petertodd/python-bitcoinlib" rel="nofollow noreferrer">Python-bitcoinlib</a> and <a href="https://github.com/sr-gi/bitcoin_tools" rel="nofollow noreferrer">bitcoin_tools</a></p>

CC BY-SA 4.0
2019-11-16T01:42:22.847Z
Thanks, I was aware of the libraries, and Peter Todd's one looks legit for this case, but all the methods there relates to script evaluation/serialization rather than to decoding the content of `decoderawtransaction` into SCRIPT. I am just confused on which method to use to get the result that's being shown by blockchain explorer.
Tony Sanak
CC BY-SA 4.0
2019-11-17T10:06:26.057Z
Not sure what method you should use in Python-bitcoinlib. You can construct a transaction or script from hex in bitcoin_tools and call the deserialize to get that representation: https://github.com/sr-gi/bitcoin_tools/blob/master/bitcoin_tools/core/script.py#L54
sr_gi
CC BY-SA 4.0
2019-11-15T18:04:18.627Z
2019-11-15T18:04:18.627Z
sr_gi
<p>Running <code>decodescript</code> on <code>d1a076722d11ddfd0fadb96d6d960b8b2ad6c6369570cd00df70a801a6be9e44</code> is returning:</p>
<pre><code>{
  &quot;asm&quot;: &quot;0 30440220278ee027abaf4720f580ce469139d75e330e120f91ff52b2c73955a712b96f3902204f11b7b1541dee5497cffd50291347b796e44ab1b6dac845d43a7185fdda184901 3045022100c3602c2872248e73f543fbf21ddc9fa3b73052261f619452fd5254852c9ea55102202c1323830f38a6fe149e0eccb18f92eba962165733285812deb96bcb8482de5d01 30450221008caaadf9b887828d02911ff22df335606c372f968d5c2ea0fa2f8c1a083fe5f502204c55eb85c0f06e10d488d7643a5c571bbabdeb935acc917836d44e755db6b1f601 532102939a016f9a4cfc4c73ba395c2baf16382a4de078dadf2bafaaac6846d786ed392102c7cf0bd62fb500d8f6ed39a46c7e72dc1b5185754e1a48d25a22195f113b35d8210306179c491a25d6db330a3a3e3ba0788b3ccea45aebfa2a06fc114787aadc01532103b8a79bd499afbc0f4b68e4c0e175176a013b1e2143da6ec95772add5c6728d6d2103bec7b18285d7af85b4f2c0936a106b746eaad14071f41788257fdffeb2e68e9a2103e4fda639ffcf2d996dc372db5eda18857afdd21054009d65ddd17ce96d5feed22103f5d1065abd2a8b5adc6ecda48712d2a572a24130b786f538629ff834b298379857ae&quot;,
  &quot;type&quot;: &quot;nonstandard&quot;,
  &quot;p2sh&quot;: &quot;32QZxW8qHSufifvr5UzXpzGG6jdcgnTCSF&quot;,
  &quot;segwit&quot;: {
    &quot;asm&quot;: &quot;0 59d0d03149e611e8f8e879ab7c1133c99091ec09758ed29a9111341e424d9891&quot;,
    &quot;hex&quot;: &quot;002059d0d03149e611e8f8e879ab7c1133c99091ec09758ed29a9111341e424d9891&quot;,
    &quot;reqSigs&quot;: 1,
    &quot;type&quot;: &quot;witness_v0_scripthash&quot;,
    &quot;addresses&quot;: [
      &quot;bc1qt8gdqv2fucg7378g0x4hcyfnexgfrmqfwk8d9x53zy6pusjdnzgsdvlm7s&quot;
    ],
    &quot;p2sh-segwit&quot;: &quot;36sk1CLrrv8HXgE1d1CKkNkwnK2tWKeWSL&quot;
  }
}
</code></pre>
<p>The original Hex:</p>
<pre><code>004730440220278ee027abaf4720f580ce469139d75e330e120f91ff52b2c73955a712b96f3902204f11b7b1541dee5497cffd50291347b796e44ab1b6dac845d43a7185fdda184901483045022100c3602c2872248e73f543fbf21ddc9fa3b73052261f619452fd5254852c9ea55102202c1323830f38a6fe149e0eccb18f92eba962165733285812deb96bcb8482de5d014830450221008caaadf9b887828d02911ff22df335606c372f968d5c2ea0fa2f8c1a083fe5f502204c55eb85c0f06e10d488d7643a5c571bbabdeb935acc917836d44e755db6b1f6014cf1532102939a016f9a4cfc4c73ba395c2baf16382a4de078dadf2bafaaac6846d786ed392102c7cf0bd62fb500d8f6ed39a46c7e72dc1b5185754e1a48d25a22195f113b35d8210306179c491a25d6db330a3a3e3ba0788b3ccea45aebfa2a06fc114787aadc01532103b8a79bd499afbc0f4b68e4c0e175176a013b1e2143da6ec95772add5c6728d6d2103bec7b18285d7af85b4f2c0936a106b746eaad14071f41788257fdffeb2e68e9a2103e4fda639ffcf2d996dc372db5eda18857afdd21054009d65ddd17ce96d5feed22103f5d1065abd2a8b5adc6ecda48712d2a572a24130b786f538629ff834b298379857ae
</code></pre>
<p><strong>Blockstream explorer is returning the script in form of OP_CODEs, my question is, is there any python library that can decode it to the same state?</strong></p>
<p><a href="https://i.sstatic.net/hIABN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hIABN.png" alt="enter image description here" /></a></p>

<script><python><input-script>
Decoding hex scriptsig in Python
Tony Sanak
# Decoding hex scriptsig in Python

(Asked by: username_0 on 2019-11-15)

Running `decodescript` on `d1a076722d11ddfd0fadb96d6d960b8b2ad6c6369570cd00df70a801a6be9e44` is returning:

```
{
  "asm": "0 30440220278ee027abaf4720f580ce469139d75e330e120f91ff52b2c73955a712b96f3902204f11b7b1541dee5497cffd50291347b796e44ab1b6dac845d43a7185fdda184901 3045022100c3602c2872248e73f543fbf21ddc9fa3b73052261f619452fd5254852c9ea55102202c1323830f38a6fe149e0eccb18f92eba962165733285812deb96bcb8482de5d01 30450221008caaadf9b887828d02911ff22df335606c372f968d5c2ea0fa2f8c1a083fe5f502204c55eb85c0f06e10d488d7643a5c571bbabdeb935acc917836d44e755db6b1f601 532102939a016f9a4cfc4c73ba395c2baf16382a4de078dadf2bafaaac6846d786ed392102c7cf0bd62fb500d8f6ed39a46c7e72dc1b5185754e1a48d25a22195f113b35d8210306179c491a25d6db330a3a3e3ba0788b3ccea45aebfa2a06fc114787aadc01532103b8a79bd499afbc0f4b68e4c0e175176a013b1e2143da6ec95772add5c6728d6d2103bec7b18285d7af85b4f2c0936a106b746eaad14071f41788257fdffeb2e68e9a2103e4fda639ffcf2d996dc372db5eda18857afdd21054009d65ddd17ce96d5feed22103f5d1065abd2a8b5adc6ecda48712d2a572a24130b786f538629ff834b298379857ae",
  "type": "nonstandard",
  "p2sh": "32QZxW8qHSufifvr5UzXpzGG6jdcgnTCSF",
  "segwit": {
    "asm": "0 59d0d03149e611e8f8e879ab7c1133c99091ec09758ed29a9111341e424d9891",
    "hex": "002059d0d03149e611e8f8e879ab7c1133c99091ec09758ed29a9111341e424d9891",
    "reqSigs": 1,
    "type": "witness_v0_scripthash",
    "addresses": [
      "bc1qt8gdqv2fucg7378g0x4hcyfnexgfrmqfwk8d9x53zy6pusjdnzgsdvlm7s"
    ],
    "p2sh-segwit": "36sk1CLrrv8HXgE1d1CKkNkwnK2tWKeWSL"
  }
}

```

The original Hex:

```
004730440220278ee027abaf4720f580ce469139d75e330e120f91ff52b2c73955a712b96f3902204f11b7b1541dee5497cffd50291347b796e44ab1b6dac845d43a7185fdda184901483045022100c3602c2872248e73f543fbf21ddc9fa3b73052261f619452fd5254852c9ea55102202c1323830f38a6fe149e0eccb18f92eba962165733285812deb96bcb8482de5d014830450221008caaadf9b887828d02911ff22df335606c372f968d5c2ea0fa2f8c1a083fe5f502204c55eb85c0f06e10d488d7643a5c571bbabdeb935acc917836d44e755db6b1f6014cf1532102939a016f9a4cfc4c73ba395c2baf16382a4de078dadf2bafaaac6846d786ed392102c7cf0bd62fb500d8f6ed39a46c7e72dc1b5185754e1a48d25a22195f113b35d8210306179c491a25d6db330a3a3e3ba0788b3ccea45aebfa2a06fc114787aadc01532103b8a79bd499afbc0f4b68e4c0e175176a013b1e2143da6ec95772add5c6728d6d2103bec7b18285d7af85b4f2c0936a106b746eaad14071f41788257fdffeb2e68e9a2103e4fda639ffcf2d996dc372db5eda18857afdd21054009d65ddd17ce96d5feed22103f5d1065abd2a8b5adc6ecda48712d2a572a24130b786f538629ff834b298379857ae

```

**Blockstream explorer is returning the script in form of OP\_CODEs, my question is, is there any python library that can decode it to the same state?**

[![enter image description here](https://i.sstatic.net/hIABN.png)](https://i.sstatic.net/hIABN.png)

**Tags:** script, python, input-script


---

## 1 answers

### Answer by username_1 on 2019-11-15. Score: 1 | Accepted answer

There are at least two I'm aware of: [Python-bitcoinlib](https://github.com/petertodd/python-bitcoinlib) and [bitcoin\_tools](https://github.com/username_1/bitcoin_tools)

> **Comments:**
> **username_0**: Thanks, I was aware of the libraries, and Peter Todd's one looks legit for this case, but all the methods there relates to script evaluation/serialization rather than to decoding the content of `decoderawtransaction` into SCRIPT. I am just confused on which method to use to get the result that's being shown by blockchain explorer.  
> **username_1**: Not sure what method you should use in Python-bitcoinlib. You can construct a transaction or script from hex in bitcoin_tools and call the deserialize to get that representation: https://github.com/username_1/bitcoin_tools/blob/master/bitcoin_tools/core/script.py#L54  

---

