bip-utils

2.12.1 · active · verified Thu Apr 16

bip-utils is an active Python library (current version 2.12.1) for generating mnemonics, seeds, private/public keys, and addresses across various cryptocurrencies, implementing standards like BIP-0039, BIP-0032, BIP-0044, BIP-0049, and BIP-0084. It sees frequent minor releases, adding support for new coins and improving existing functionalities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates generating a 12-word BIP39 mnemonic, converting it into a seed, and then deriving the first external Bitcoin address using BIP44 derivation path standards.

from bip_utils import Bip39MnemonicGenerator, Bip39SeedGenerator, Bip44, Bip44Coins, Bip39WordsNum

# 1. Generate a random BIP39 mnemonic of 12 words
mnemonic = Bip39MnemonicGenerator().FromWordsNumber(Bip39WordsNum.WORDS_NUM_12)
print(f"Generated Mnemonic: {mnemonic}")

# 2. Generate a seed from the mnemonic (optional passphrase)
# For production, use a strong passphrase, or an empty string if none.
# os.environ.get('BIP_MNEMONIC_PASSPHRASE', '')
passphrase = ""
seed_bytes = Bip39SeedGenerator(mnemonic).Generate(passphrase)
print(f"Generated Seed (hex): {seed_bytes.hex()}")

# 3. Derive a Bitcoin (BIP44) address from the seed
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.BITCOIN)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0) # Account 0
bip44_chain_ctx = bip44_acc_ctx.Change(0) # External chain
bip44_addr_ctx = bip44_chain_ctx.AddressIndex(0) # First address

print(f"Bitcoin BIP44 Address: {bip44_addr_ctx.PublicKey().ToAddress()}")

view raw JSON →