Registry / serialization / bt-decode

bt-decode

JSON →
library0.8.0pypypi✓ verified 85d ago

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.

pip install bt-decode
INSTALL
IMPORT
SIG · BT-DECODE
B
bt-decode
serializationpythonv0.8.0
Install
1.7s avg
Import
Disk
18MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.7s · import 0.000s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DelegateInfo
from bt_decode import DelegateInfo
NeuronInfo
from bt_decode import NeuronInfo
NeuronInfoLite
from bt_decode import NeuronInfoLite
SubnetInfo
from bt_decode import SubnetInfo

This quickstart demonstrates how to initialize a (mock) Bittensor subtensor connection and use `bt_decode.DelegateInfo.decode_from_bytes` to parse a raw hexadecimal byte string representing Bittensor delegate information into a structured Python object. This pattern is similar for other Bittensor data structures like `NeuronInfo`.

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}")
Debug
Known issues
breakingThe `AccountId` decoding functionality was removed in version 0.8.0. Code relying on direct `AccountId` decoding will break.
fix
Review your code for `AccountId` decoding and adapt to alternative methods provided by the library or handle its removal appropriately. Consult the Bittensor documentation for updated data structures if needed.
affects: >=0.8.0
gotchaFeatures 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.
fix
Exercise caution when using string-based decoding/encoding. Prefer explicitly defined data structure classes (e.g., `DelegateInfo`) if available and stable. Monitor changelogs for updates on these features if you rely on them.
affects: >=0.8.0
gotchaCompatibility 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.
fix
Ensure you upgrade to `bt-decode` version 0.8.0 or newer if you are using or planning to use Python 3.14.
affects: <0.8.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'bt_decode'
The 'bt-decode' package is either not installed, or Python cannot find it in the current environment's search path.
fix
Install the package using pip: `pip install bt-decode`. If using a virtual environment, ensure it is activated.
AttributeError: 'str' object has no attribute 'decode'
The '.decode()' method is being called on a Python string (str) object, but in Python 3, this method is only available for bytes objects. The bt-decode library likely expects bytes as input for its decoding functions.
fix
Ensure that the data being passed to bt-decode's functions, or any data you intend to decode, is a bytes object. If you have a hexadecimal string, convert it to bytes first (e.g., `bytes.fromhex(hex_string)`).
ERROR: Could not build wheels for bt-decode
During installation, pip failed to compile the underlying Rust code because necessary build tools for Rust (cargo) or C/C++ compilers are missing on your system.
fix
Install Rust and Cargo (recommended via `rustup.rs`) and ensure your system has C/C++ build tools (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual C++ Build Tools on Windows).
error: externally-managed-environment × This environment is externally managed
On certain Linux distributions (like Debian/Ubuntu), pip prevents global package installation outside of virtual environments to avoid conflicts with system-managed Python packages, adhering to PEP 668.
fix
Create and activate a Python virtual environment (`python3 -m venv .venv && source .venv/bin/activate`) and then install the package within it (`pip install bt-decode`). Alternatively, if you understand the risks, you can override this by using `pip install --break-system-packages bt-decode`.
Upgrade
Version history
0.8.0latest on PyPI · released Oct 28, 2025
Audit
Dependencies
bittensoroptionalCommonly used in conjunction with bt-decode for setting up a subtensor connection to fetch data for decoding.
Agent activity
55 hits · last 30 days
node
52
Bingbot
1
OpenAI (training)
1
Resources
bt-decode — pip install bt-decode · libregistry