Bittensor Data Structure Decoder
bt-decode is a Python wrapper around the high-performance Rust `scale-codec` crate, designed for rapid scale-decoding of Bittensor data structures. As of version 0.8.0, it provides essential tools to decode various Bittensor-specific information, including `DelegateInfo`, `NeuronInfo`, `NeuronInfoLite`, and `SubnetInfo`. The library maintains an active development and release cadence, with frequent updates to ensure compatibility and introduce new features.
Warnings
- breaking The `AccountId` decoding functionality was removed in version 0.8.0. Code relying on direct `AccountId` decoding will break.
- gotcha Features for 'decode by type string' and 'encode by type string' are marked as unstable. While they may work for multiple types, their API or behavior might change in future releases without major version bumps.
- gotcha Compatibility for Python 3.14 was explicitly added in version 0.8.0. Users on older `bt-decode` versions (prior to 0.8.0) might encounter issues or lack full support when running with Python 3.14.
Install
-
pip install bt-decode
Imports
- DelegateInfo
from bt_decode import DelegateInfo
- NeuronInfo
from bt_decode import NeuronInfo
- NeuronInfoLite
from bt_decode import NeuronInfoLite
- SubnetInfo
from bt_decode import SubnetInfo
Quickstart
import bittensor
from bt_decode import DelegateInfo
# NOTE: For a real scenario, 'subtensor' would connect to a Bittensor network
# and 'hex_bytes_result' would be actual data fetched from the chain.
# This example uses placeholder data for demonstration.
# Setup a mock subtensor connection (in a real app, this would connect)
class MockSubtensor:
def __init__(self):
pass
def get_delegated_v2(self, *args, **kwargs):
# This is placeholder hex bytes for a DelegateInfo object
# In a real scenario, this would come from a live Bittensor chain.
# The actual bytes would vary.
return "0x0c00000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000200000000000000020000000000000003000000000000000300000000000000"
subtensor = MockSubtensor()
# Assume we fetched raw hex bytes (e.g., from subtensor.get_delegated_v2())
# This is a simplified placeholder.
raw_hex_bytes = subtensor.get_delegated_v2() # Example call
# Decode the raw hex bytes using DelegateInfo
try:
decoded_delegate_info = DelegateInfo.decode_from_bytes(bytes.fromhex(raw_hex_bytes[2:]))
print(f"Successfully decoded DelegateInfo: {decoded_delegate_info}")
except Exception as e:
print(f"Error decoding: {e}")