Skip to main content

Bitcoin utility functions

Project description

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.2) 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 and non-standanrd transactions where tested. 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.

Installation

$ pip install bitcoin-utils

Examples

Keys and Addresses

https://github.com/karask/python-bitcoin-utils/blob/master/examples/keys_addresses.py - 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

https://github.com/karask/python-bitcoin-utils/blob/master/examples/keys_segwit_addresses.py - creates P2WPKH, P2SH-P2WPKH, P2WSH and P2SH-P2WSH addresses.

Create a P2PKH Transaction

https://github.com/karask/python-bitcoin-utils/blob/master/examples/p2pkh_transaction.py - creates a simple transaction with one input and two outputs.

Create a P2PKH Transaction with different SIGHASHes

https://github.com/karask/python-bitcoin-utils/blob/master/examples/multi_input_sighash_transaction.py - creates a 2-input 2-output transaction with different signature types.

Create a P2SH Address

https://github.com/karask/python-bitcoin-utils/blob/master/examples/send_to_p2sh_transaction.py - creates a P2SH address that corresponds to a P2PK redeem script and sends some funds to it.

Create (spent) a P2SH Transaction

https://github.com/karask/python-bitcoin-utils/blob/master/examples/spend_p2sh_transaction.py - creates a transaction that spends a P2SH output.

Create a non-standard tx

https://github.com/karask/python-bitcoin-utils/blob/master/examples/create_non_std_tx.py - sends funds to an address with a non-standard tx (script: OP_ADD OP_5 OP_EQUAL)

Spend a non-standard tx

https://github.com/karask/python-bitcoin-utils/blob/master/examples/spend_non_std_tx.py - spends funds from script OP_ADD OP_5 OP_EQUAL

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitcoin-utils-0.2.2.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

bitcoin_utils-0.2.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file bitcoin-utils-0.2.2.tar.gz.

File metadata

  • Download URL: bitcoin-utils-0.2.2.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for bitcoin-utils-0.2.2.tar.gz
Algorithm Hash digest
SHA256 74649aea0d2a08509e72d2e695b51e5e3097a7faf1a47641271e1aaba795c11e
MD5 9b1ecb015c23926296a56fda33c00964
BLAKE2b-256 13b61b117c3b0fe8d78fdc3757096d2d19c2d11b29599de3550e65f22610aeb8

See more details on using hashes here.

File details

Details for the file bitcoin_utils-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: bitcoin_utils-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for bitcoin_utils-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 71d10c4d6d320fd847c2d6625bea5a087e90dcd649ad0f460e4f920e26bf9efb
MD5 32e5bc895946a01c2807ecc5a8cf2397
BLAKE2b-256 a1d7759bd79982463f48131c537cbbf39fd9a94269ab8a6c2d817e5eef811fe0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page