bip-utils
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
-
NameError: name 'NeoAddrEncoder' is not defined
cause The `NeoAddrEncoder` class was renamed to `NeoLegacyAddrEncoder` in `bip-utils` v2.10.0.fixChange `from bip_utils import NeoAddrEncoder` to `from bip_utils import NeoLegacyAddrEncoder` and update all usages of `NeoAddrEncoder` in your code. -
ModuleNotFoundError: No module named 'ed25519_blake2b'
cause The `ed25519-blake2b` dependency was replaced by `ed25519-blake2b-fork` in `bip-utils` v2.12.1.fixEnsure your `bip-utils` installation is up-to-date (`pip install --upgrade bip-utils`). The new dependency `ed25519-blake2b-fork` should be installed automatically. -
ERROR: Failed building wheel for coincurve
cause The `coincurve` package requires specific C/C++ compilation tools that are missing on your system.fixInstall the necessary build tools for your operating system. For Debian/Ubuntu: `sudo apt-get install build-essential`. For macOS: `xcode-select --install`. For Windows: Install 'Microsoft Visual C++ Build Tools'. Alternatively, you can force `bip-utils` to use `ecdsa` (pure Python, but slower) by setting `USE_COINCURVE = False` in `bip_utils/ecc/conf.py` (after installing `ecdsa` via `pip install ecdsa`) and then reinstall `bip-utils`.
Warnings
- breaking The `NeoAddrEncoder` class was renamed to `NeoLegacyAddrEncoder` in `v2.10.0`. Using the old name will result in a `NameError`.
- breaking The `ed25519-blake2b` dependency was replaced by `ed25519-blake2b-fork` in `v2.12.1`. While this change primarily improved Windows installation by including wheels, direct references or older installations might cause import issues.
- gotcha Installation of `coincurve` (a default dependency for secp256k1 operations) can fail due to requiring compilation tools (e.g., C++ compiler).
- breaking The generic `Bip32` class was removed and replaced by specific curve-dependent classes (e.g., `Bip32Ed25519Slip`, `Bip32Secp256k1`) starting from `v2.2.0`. Older code using `Bip32` directly will break.
Install
-
pip install bip-utils
Imports
- Bip39MnemonicGenerator
from bip_utils import Bip39MnemonicGenerator
- Bip39SeedGenerator
from bip_utils import Bip39SeedGenerator
- Bip44
from bip_utils import Bip44
- Bip44Coins
from bip_utils import Bip44Coins
- Bip39WordsNum
from bip_utils import Bip39WordsNum
- NeoAddrEncoder
from bip_utils import NeoAddrEncoder
from bip_utils import NeoLegacyAddrEncoder
Quickstart
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()}")