Skip to main content

Bitcoin SPV implementation in Python

Project description


__WARNING__: This is experimental software. Use at your own risk

pyspv is a no-bullshit, easy-to-use Python module implementing the full Bitcoin SPV client protocol. Connecting to the Bitcoin network is as easy as:

`python import pyspv spv = pyspv.pyspv("my-application-name") ... `

… but just connecting to the Bitcoin network would be boring. The real goal of this project is to make embedding Bitcoin into your project so simple that everybody does it. pyspv handles the details like Blockchain syncing, the peer-to-peer network, payment management, wallets, etc., and allows you to get started prototyping your Bitcoin application quickly.

I intend to make this SPV client as extensible as possible with a goal of supporting alt-coins using simple coin definitions. Because pyspv is modular, it is now easy to connect to several different alt-coin networks within the same application – simply initialize two pyspv classes with different coin definitions.

You can develop a pretty UI wallet or just a simple utility to send you an E-mail you when an address receives a payment. The possibilities are really endless.


pyspv only relies on a small handful of dependencies:

  • [Python 3.3]( :: It probably works on other versions, but this is my testing platform.
  • OpenSSL :: You’ll need (Linux/Mac) or libeay32.dll (Windows) in your path.
  • [Bitarray]( :: This is required by the bloom filter implementation.


  • SPV implementation, so relatively lightweight
  • Python, useful for server and user applications
  • Multisignature support, can create, send to and spend multisignature payments
  • Stealth address support, can create, send to and spend stealth address payments
  • Tor/SOCKS support
  • Testnet support
  • Extensible payment monitor and transaction building system


This example runs a basic wallet. Running it with no arguments starts an RPC server. With arguments, an RPC call is made. The program behaves similarly to bitcoind, with several noticeable differences.

Available commands:

  • getnewaddress [label]? - returns a standard public-key-hash address
  • getnewstealthaddress [label]? - returns a new stealth address
  • getnewpubkey [label]? [compressed=false]? - returns a new public key (hex)
  • getbalance - returns total balance in the wallet
  • getinfo - returns information on the state of the SPV node
  • listspends [include_spent=false] - returns a dictionary describing the Spends in the wallet
  • sendtoaddress [address] [amount] [memo]? - sends amount of coins to address. The address can be a stealth address, a multisig address, or a standard address.
  • sendspendtoaddress [spend_hash] [address] [amount] [memo]? - force inclusion of a specific Spend to the specified address. more coins are selected from the wallet if they’re needed to complete the transaction.
  • dumppubkey [address] - yield the public key of the specified address, if it’s in the wallet
  • dumpprivkey [address] - yield the private key (in WIF format) of the specified address, if it’s in the wallet
  • genmultisig [nreq] [mtotal] [pubkey1,pubkey2,…]? - produce a new multsignature address. If not mtotal public keys are provided, new ones are generated and stored in the wallet. The multisignature address requires nreq signatures to spend.
  • sendrawtransaction [tx_hex] - broadcast a transaction to the network

This example runs through the math and demonstrates how stealth addresses work in theory.

Create a new transaction with specified outputs and zero inputs. The transaction displayed can be used as input to

Given a transaction and a spend id, add those inputs and sign them using ANYONECANPAY. This program, combined with effectly allows easy creation of [assurance contracts](



Documentation will soon be available at

Project details

Release history Release notifications

This version
History Node


Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page