A Bitcoin python library for private + public keys, addresses, transactions, & RPC
Latest commit 9ae53da Nov 22, 2016 @shea256 shea256 committed on GitHub Merge pull request #58 from blockstack/circleci
add in circle.yml



CircleCI PyPI PyPI PyPI Slack

Python library with tools for Bitcoin and other cryptocurrencies.


Private Keys

>>> from pybitcoin import BitcoinPrivateKey
>>> private_key = BitcoinPrivateKey()
>>> private_key.to_hex()
>>> private_key.to_wif()
>>> private_key_2 = BitcoinPrivateKey('91149ee24f1ee9a6f42c3dd64c2287781c8c57a6e8e929c80976e586d5322a3d')
>>> print private_key.to_wif() == private_key_2.to_wif()

Public Keys

>>> public_key = private_key.public_key()
>>> public_key.to_hex()
>>> public_key_2 = BitcoinPublicKey(public_key.to_hex())
>>> print public_key.to_hex() == public_key_2.to_hex()


>>> public_key.address()
>>> public_key.hash160()

Brainwallet-based Private Keys

>>> private_key = BitcoinPrivateKey.from_passphrase()
>>> private_key.passphrase()
'shepherd mais pack rate enamel horace diva filesize maximum really roar mall'
>>> private_key.to_hex()
>>> priv2 = BitcoinPrivateKey.from_passphrase(priv2.passphrase())
>>> print private_key.to_hex() == priv2.to_hex()

Sending Transactions to Addresses

>>> from pybitcoin import BlockcypherClient
>>> recipient_address = '1EEwLZVZMc2EhMf3LXDARbp4mA3qAwhBxu'
>>> blockchain_client = BlockcypherClient(BLOCKCYPHER_API_KEY)
>>> send_to_address(recipient_address, 10000, private_key.to_hex(), blockchain_client)

Sending OP_RETURN Transactions

>>> from pybitcoin import make_op_return_tx
>>> data = '00' * 80
>>> tx = make_op_return_tx(data, private_key.to_hex(), blockchain_client, fee=10000, format='bin')
>>> broadcast_transaction(tx, blockchain_client)
{"success": True}


>>> class NamecoinPrivateKey(BitcoinPrivateKey):
>>>     _pubkeyhash_version_byte = 52
>>> namecoin_private_key = NamecoinPrivateKey(private_key.to_hex())
>>> namecoin_private_key.to_wif()
>>> namecoin_public_key = namecoin_private_key.public_key()
>>> namecoin_public_key.address()

Supported currencies

Litecoin, Namecoin, Peercoin, Primecoin, Testnet, Worldcoin, Megacoin, Feathercoin, Terracoin, Novacoin, Dogecoin, Anoncoin, Protoshares, Ixcoin, Memorycoin, Infinitecoin, Cryptogenic Bullion, Quarkcoin, Netcoin, Earthcoin, Reddcoin, (insert your favorite cryptocurrency here)


Q: Can I contribute to pybitcoin?

A: Of course! Any and all are encouraged to contribute. Just fork a copy of the repo and get started on something that you think would improve the current offering.

Q: What should I work on?

A: That's up to you! For a quick project, consider adding support for a new cryptocurrency (should only require two lines of code, not including the unit tests).

Meanwhile, for something a bit more ambitious, check the issues section for outstanding feature requests.


pybitcoin is still in beta. Developers using pybitcoin are encouraged to inspect the code for themselves and perform their own tests. We are committed to ensuring that this library behaves exactly as it is supposed to under all conditions, and have plans to ramp up our testing efforts going forward.