Skip to main content

bitoplens

A pure-Python Bitcoin Script simulator and visualizer. bitoplens executes Bitcoin scripts step-by-step on a virtual machine, records the full machine state at every opcode, and renders an interactive, self-contained HTML page that lets you step through the execution and inspect the stack, the transaction, and (for Taproot) the script tree.

  • Pure Python, no native build. Zero pip runtime dependencies. secp256k1 crypto is provided by secp256k1lab, vendored as a git submodule (also pure Python).
  • Full script coverage: legacy (P2PK / P2PKH / P2SH / multisig), SegWit v0 (P2WPKH / P2WSH, BIP143), and Taproot (P2TR key-path & script-path, Schnorr BIP340, tapscript BIP342, BIP341 sighash).
  • Introspectable interpreter: the VM is a stepper; every step captures the main stack, alt stack, conditional (OP_IF) state, and signature-check details — the same data feeds both the Python API and the HTML viewer.

Quick start

import bitoplens as bl
from bitoplens.script import opcodes as OP
from bitoplens.script.script import ScriptBuilder
from bitoplens.primitives.hashing import sha256

# A hash-preimage lock, no transaction needed.
spk = ScriptBuilder().op(OP.OP_SHA256).push(sha256(b"open sesame")).op(OP.OP_EQUAL).build()
sig = ScriptBuilder().push(b"open sesame").build()

trace = bl.run_script(spk, sig)
print(trace.valid)                 # True
bl.visualize(trace, "trace.html")  # self-contained interactive HTML

For full transaction verification (legacy, SegWit v0, Taproot) use bl.run(script_pubkey, tx=..., input_index=..., spent_outputs=..., flags=...). See examples/demo.py.

Visualize a real transaction

scripts/visualize_tx.py fetches a transaction (and each input's previous output) from mempool.space, verifies every input, and writes an interactive HTML trace — standard library only, no extra dependencies:

python scripts/visualize_tx.py <txid> --open        # render input 0, open in browser
python scripts/visualize_tx.py <txid> --input 2     # a specific input
python scripts/visualize_tx.py <txid> --network testnet --tx-only

It prints a per-input verdict, e.g.:

tx f4184fc5…31e9e16  (mainnet)  1 in / 2 out
  input 0: OK   OK                     P2PK

Install

pip install bitoplens

To install the latest development version directly from GitHub, use pip install git+https://github.com/elmeriniemela/bitoplens.git.

Development

git submodule update --init --recursive   # if cloning fresh
pip install -e '.[dev]'

Releasing

Releases are published to PyPI by GitHub Actions using trusted publishing. To publish a version:

  1. Update version in pyproject.toml and __version__ in src/bitoplens/__init__.py.
  2. Push the change and wait for the test workflow to pass.
  3. Create and push a tag matching the version, for example v0.1.0.

The pypi GitHub environment must be configured as a trusted publisher for the elmeriniemela/bitoplens repository and the publish.yml workflow. The publish workflow can also be run manually to validate the release build; manual runs do not upload to PyPI.

Testing

The interpreter is validated against upstream consensus vectors, vendored under tests/data/:

  • Bitcoin Core script_tests.json — all ~1230 runnable cases pass with an exact ScriptError match (dynamically-synthesized Taproot rows are skipped).
  • BIP341 wallet vectors — Taproot output-key derivation, sighash midstates, key-path sighashes, and full verification against real Schnorr signatures.
  • The real block-170 transaction (historic P2PK) plus constructed spends for every script type.
pytest -q

Metadata

Release files for bitoplens 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitoplens 0.1.0
File Size Uploaded Provenance Actions
bitoplens-0.1.0.tar.gz 64.3 kB With provenance Details for bitoplens-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitoplens 0.1.0
File Interpreter ABI Platform Actions
bitoplens-0.1.0-py3-none-any.whl Python 3 none any Details for bitoplens-0.1.0-py3-none-any.whl

Total release size: 127.7 kB

Release files / bitoplens-0.1.0.tar.gz

Download URL bitoplens-0.1.0.tar.gz
Size 64.3 kB
Tags Source
SHA-256 checksum
How to use checksums
15e9450e9471bf2066f368fba7f92dd71cdfec3f6ac168dc92d5e806448ad0f6
BLAKE2b-256 checksum
How to use checksums
693f0ba17f29b585fb9275e0928b631d9b07ea8db0fff76cb270c9e963a9f25d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Release files / bitoplens-0.1.0-py3-none-any.whl

Download URL bitoplens-0.1.0-py3-none-any.whl
Size 63.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c28f51127cae85dcb63540a791d878f2ec6c2fd04aa7d020f586a83aca0ef66e
BLAKE2b-256 checksum
How to use checksums
fd12cc89a2d2777ff31f58d721e6cd21577e67f34906c752541b485b290ca71d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

Security for bitoplens 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bitoplens-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page