Bittensor Python SDK

raw JSON →
10.2.1 verified Mon Apr 27 auth: no python

Python SDK for the Bittensor decentralized machine learning network. Allows interaction with the Bittensor blockchain, manage wallets, stake, register neurons, and query the metagraph. Version 10.2.1 is the current stable release. The library is actively maintained with frequent releases.

pip install bittensor
error ModuleNotFoundError: No module named 'bittensor.bittensor'
cause In v10+, the module structure changed. The old bittensor.bittensor module is removed.
fix
Use import bittensor as bt and access bittensor.core instead.
error TypeError: __init__() got an unexpected keyword argument 'max_retries'
cause The 'max_retries' parameter was renamed to 'max_attempts' in v10.0.0rc3.
fix
Replace max_retries with max_attempts in the call.
error bittensor.errors.NetworkError: Cannot connect to network 'finney'
cause The default network 'finney' may be unreachable or require correct endpoint configuration.
fix
Specify a valid network like 'test' or set environment variable BITTENSOR_NETWORK.
breaking In v10.0.0, many APIs were restructured. The old bittensor.bittensor and bittensor.utils modules are removed. Use bittensor.core instead.
fix Update imports: from bittensor.core import ... instead of bittensor.bittensor.
breaking The 'max_retries' parameter was renamed to 'max_attempts' in v10.0.0rc3. Using the old name will cause a TypeError.
fix Rename max_retries to max_attempts in your code.
gotcha When using bt.subtensor() to get a Subtensor instance, you must specify the 'network' argument. Failing to do so uses 'finney' (mainnet) by default, which may incur fees.
fix Always pass network='test' for testnet or network='local' for local nodes.
deprecated The 'bt.bittensor' module is deprecated. Use 'bt.core' for internal SDK functions.
fix Replace bt.bittensor with bt.core in imports.

Connects to the Bittensor test network, creates/generates a wallet, and prints the subnet 1 metagraph and balance.

import bittensor as bt

# Connect to the network (finney testnet or mainnet)
subtensor = bt.subtensor(network='test')

# Create a wallet (will prompt for password if new)
wallet = bt.Wallet(name='test-wallet')

# Get the metagraph for subnet 1
metagraph = subtensor.metagraph(1)
print('Subnet 1 metagraph:', metagraph)

# Check hotkey balance
balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
print('Balance:', balance)