BIP32 (Bitcoin HD Wallets)
BIP32 is a minimalistic Python implementation of the Bitcoin HD wallet (Hierarchical Deterministic Wallet) specification. The current version is 5.0.0, released in November 2025. The library maintains an active development cycle, with occasional major releases that often introduce breaking changes, typically driven by updates to Python versions or the implementation of stricter sanity checks.
Warnings
- breaking Version 5.0.0 introduced breaking changes. Always consult the `CHANGELOG.md` for specific migration instructions when upgrading from previous major versions.
- breaking Version 3.0.0 was a breaking release due to updates in Python and Coincurve version requirements. This may necessitate updating your Python environment or `coincurve` dependency.
- breaking Version 2.0.0 introduced stricter sanity checks and renamed methods within the `BIP32` class. Code relying on older method names or less stringent input validation will break.
- gotcha When initializing `BIP32` from an extended public key (`from_xpub`), you can only derive unhardened child public keys. Attempting to derive hardened public keys will result in an error, as this operation requires the private key.
- gotcha The `bip32` library depends on `coincurve`, which is a Python wrapper for the `libsecp256k1` C library. This means that system-level dependencies for `libsecp256k1` might be required for successful installation, particularly on certain operating systems or custom environments.
Install
-
pip install bip32
Imports
- BIP32
from bip32 import BIP32
- HARDENED_INDEX
from bip32 import HARDENED_INDEX
Quickstart
from bip32 import BIP32, HARDENED_INDEX
# Create a BIP32 instance from a seed
seed = bytes.fromhex("000102030405060708090a0b0c0d0e0f")
bip32_wallet = BIP32.from_seed(seed)
# Derive a hardened private child key using a list of indices
xpriv_path_list = bip32_wallet.get_xpriv_from_path([1, HARDENED_INDEX, 9998])
print(f"Derived XPRIV (list path): {xpriv_path_list}")
# Derive a hardened private child key using a string path
xpriv_path_str = bip32_wallet.get_xpriv_from_path("m/1/0'/9998")
print(f"Derived XPRIV (string path): {xpriv_path_str}")
# Derive an extended public key (xpub) from a non-hardened path
xpub = bip32_wallet.get_xpub_from_path("m/0/0/0")
print(f"Derived XPUB: {xpub}")
# Instantiate from an existing extended public key (xpub) (can only derive unhardened children)
public_wallet = BIP32.from_xpub(xpub)
child_xpub = public_wallet.get_xpub_from_path("m/0/1")
print(f"Derived child XPUB from XPUB: {child_xpub}")