Library to interact with the Bitcoin network. Ideal for low-level learning and experimenting.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples really small integers are now added as the appropriate OP CODES (0-16) Feb 17, 2019
LICENSE updated LICENSE, README.rst and fixed bug when generating random priv… Oct 18, 2018



This is a bitcoin library that provides tools/utilities to interact with the Bitcoin network. One of the primary goals of the library is to explain the low-level details of Bitcoin. The code is easy to read and properly documented explaining in detail all the thorny aspects of the implementation. It is a low-level library which assumes some high-level understanding of how Bitcoin works. In the future this might change.

This is an early version of the library (v0.2.5) and currently, it supports private/public keys, all type of addresses (incl.segwit) and creation of P2PKH and P2SH transactions (with all SIGHASH types). All script op codes are included. Timelock and non-standanrd transactions are supported. More functionality will be added continuously and the documentation will be improved as the work progresses.

The API documentation can be build with Sphinx but is also available as a PDF for convenience. One can currently use the library for experimenting and learning the inner workings of Bitcoin. It is not meant for production yet and parts of the API might be updated with new versions.


$ pip install bitcoin-utils


Keys and Addresses - creates a private key which we use to derive a public key and in turn an address. We also use the private key to sign a message and then verify it using the public key.
Segwit Addresses - creates P2WPKH, P2SH-P2WPKH, P2WSH and P2SH-P2WSH addresses.
Create a P2PKH Transaction - creates a simple transaction with one input and two outputs.
Create a P2PKH Transaction with different SIGHASHes - creates a 2-input 2-output transaction with different signature types.
Create a P2SH Address - creates a P2SH address that corresponds to a P2PK redeem script and sends some funds to it.
Create (spent) a P2SH Transaction - creates a transaction that spends a P2SH output.
Create a non-standard tx - sends funds to an address with a non-standard tx (script: OP_ADD OP_5 OP_EQUAL)
Spend a non-standard tx - spends funds from script OP_ADD OP_5 OP_EQUAL
Create a P2SH address with a relative timelock - creates a P2SH address that locks funds (sent to it) with a private key (P2PKH) and a relative locktime of 200 blocks in the future.
Spend from a timelocked address - spends from a P2SH(CSV+P2PKH) address as created from above.

Please explore the codebase or the API documentation (BitcoinUtilities.pdf) for supported functionality and other options.