Skip to content
btx
Pure-Python · secp256k1 · No network required

The Bitcoin stack,
parsed at the byte.

A precision Python toolkit for parsing raw transactions, extracting ECDSA and Schnorr signatures, and analysing nonce reuse on the secp256k1 curve — with zero runtime dependencies and an all-public API.

pip install btx · Python 3.12 — 3.14
Tests passing
886
Code coverage
99%+
Runtime deps
0
Python
3.12+
btx — extract signatures
~/btx
$ btx extract 0200000001... --json

  "txid": "9f2c...8e44",
  "inputs": [
    "index": 0,
    "script_type": "P2WPKH",
    "r": "c8b3...4a2f",
    "s": "1d6e...92bc",
    "z": "7a91...05d3",
    "verified": true
  ]

$ btx health
 curve ops         ok
 sighash           ok
 psbt              ok
 backend: native   3.41 ms/op
secp256k1 · y² = x³ + 7 G · 256-bit
p = 2²⁵⁶ − 2³² − 977 n = 0xffff…fecd
Built for Security researchers · Wallet engineers · Forensic analysts · Cryptography teams
Capabilities

Every layer of the stack. Audited, layered, public.

btx is organised as a strict dependency pyramid. Each layer is understandable and testable in isolation — no hidden behaviour, no semi-private helpers.

Transaction parsing

Legacy, SegWit v0 (BIP-143) and Taproot (BIP-341) wire formats — parsed with deterministic, well-tested code paths.

01 learn more →

Signature extraction

ECDSA and Schnorr from every standard script type: P2PK, P2PKH, P2SH-multisig, P2WPKH, P2WSH, nested SegWit and Taproot key & script paths.

02 learn more →

Pluggable curve backends

Pure Python by default. Swap in libsecp256k1 via coincurve for production throughput — same API, no rewrites.

03 learn more →

Nonce-reuse analysis

Linearised ECDSA (α, β) relations with both same-nonce and related-nonce recovery — the algebra behind real-world key extraction.

04 learn more →

PSBT pipeline

BIP-174 parse, edit, sign and extract. Process batches of PSBTs with ThreadPool or ProcessPool executors and graceful shutdown.

05 learn more →

Air-gap friendly

Zero runtime dependencies. Network I/O lives in an isolated services layer — the core library is import-safe offline.

06 learn more →
In your hands

One library,
the entire surface.

From a 60-character CLI to a deeply programmable Python API. Same precision underneath, no half-implemented corners.

  • Deterministic parsing — no hidden state, no global caches.
  • Frozen dataclasses with slots — value semantics out of the box.
  • All-public API — no chasing _foo through submodules.
$ btx extract 0200000001...
txid     = 9f2c…8e44
inputs   = 2
sigs     = 2
verified = true
  [0] P2WPKH  r=c8b3…4a2f  s=1d6e…92bc
  [1] P2TR    taproot key-path  z=7a91…05d3
python · btx
Architecture

Layered like the protocol itself.

Strict dependency rules mean each layer can be reasoned about and tested in isolation. No upward dependencies. No cross-layer leakage.

btx/

btx.cli

Typer-based command-line interface

decode extract linearize broadcast health

btx.services

Blockchain data providers + async batch

Blockstream Mempool.space blockchain.info generic HTTP

btx.signature

Extraction · linearisation · attacks · signing

ECDSA Schnorr nonce reuse verifier plugin registry

btx.descriptor · psbt · sighash · transaction · script

Transaction, script and PSBT machinery

BIP-174 BIP-341 BIP-143 miniscript builder

btx.encoding · field · curve

Byte-level, modular arithmetic & secp256k1 point ops

hex · varint · DER · SEC inverse · sqrt point · dispatch · batch

No upward refs

Higher layers never depend on lower ones — enforced by tests.

No network in core

Only the services layer touches I/O. Core is import-safe offline.

Pluggable backends

Pure-Python by default, libsecp256k1 for production throughput.

Security posture

Cryptography deserves
cryptography-grade rigor.

btx is built for environments where correctness is not optional. Each layer is testable in isolation, each helper has a public name, and there are no surprises buried in private modules.

Air-gappable by default

Network I/O is opt-in and isolated. The core library imports cleanly in fully offline environments — perfect for forensic and hardware workflows.

Deterministic, auditable code

Strict type hints, mypy in strict-ish mode, and 99%+ test coverage across the curve, encoding, and signature layers.

No silent behaviour

Every helper is a documented public symbol — re-exported from the package root. No _foo chase, no surprises.

Reference implementation SEC-2 v2.0
Curve
y² = x³ + 7 (mod p)
Prime
p = 2²⁵⁶ − 2³² − 977
Order
n = 0xFFFFFFFF…FFFFFECD
Generator G
Gx = 0x79BE…02A7F3
Gy = 0x483A…D916CA
Conforms to SEC-2 v2.0 View spec
By the numbers

Built with the same care
you bring to your code.

Public benchmarks on every push. 99%+ coverage across the public API. A clean slate for your most demanding Bitcoin workloads.

Tests passing
886

pytest + Hypothesis

Test coverage
99%

across the core stack

Runtime deps
0

Typer is the only one

Per-curve-op
3.41ms

native backend · median

Standards implemented

BIP-141 · Segregated Witness
BIP-143 · SegWit v0 sighash
BIP-174 · PSBT format
BIP-340 · Schnorr signatures
BIP-341 · Taproot
RFC-6979 · Deterministic ECDSA
Where teams use it

One library. Many surfaces.

From incident response to wallet R&D — btx fits in wherever Bitcoin primitives need to be reasoned about, not just called.

Security

Forensic analysis

Parse blocks, extract every signature, and search for nonce reuse across millions of transactions — all in pure Python.

Wallets

Wallet engineering

Construct, sign and broadcast transactions with immutable value semantics and a fully public, predictable API.

Research

Research & education

Read the byte-level wire format with code that mirrors the BIPs. Ideal for teaching secp256k1 from the ground up.

Compliance

Compliance tooling

Batch-process PSBTs, classify scripts, and verify signatures deterministically — without touching the network.

Ready when you are

Install btx.
Ship something serious.

One line of pip. Zero dependencies. A Bitcoin-grade toolkit that behaves the way cryptography should.

$ pip install btx
pip pip install btx
· uv uv add btx
· poetry poetry add btx