Bittensor CLI

9.20.1 · active · verified Thu Apr 16

bittensor-cli is the official command-line interface for interacting with the Bittensor network. It allows users to manage wallets, stake TAO, register hotkeys, manage subnets, and perform other on-chain operations. As of version 9.20.1, it provides robust tools for participants in the decentralized AI network, with frequent updates addressing bug fixes and new features.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates how to programmatically execute `btcli` commands using Python's `subprocess` module, as bittensor-cli is primarily a command-line interface. It checks the CLI version and attempts to list subnets. Note that for actual network operations, a running subtensor node or a public endpoint is required.

import subprocess
import json
import sys

# Note: bittensor-cli is primarily a command-line tool.
# This quickstart demonstrates how to run a command programmatically.

try:
    # Get the installed btcli version
    version_process = subprocess.run(
        [sys.executable, '-m', 'btcli', 'version'],
        capture_output=True, text=True, check=True
    )
    print(f"Bittensor CLI Version:\n{version_process.stdout}")

    # List available subnets in JSON format
    # This command requires a connection to the Bittensor network.
    # Replace 'finney' with your preferred network, e.g., 'local' for a local setup.
    print("\nListing subnets on 'finney' network...")
    subnets_process = subprocess.run(
        [sys.executable, '-m', 'btcli', 'subnets', 'list', '--netuid', '0', '--json-out', '--no-prompt', '--subtensor.chain_endpoint', 'ws://127.0.0.1:9944'], # Example using local, replace as needed
        capture_output=True, text=True, check=False # check=False to catch potential errors gracefully
    )

    if subnets_process.returncode == 0:
        try:
            subnets_data = json.loads(subnets_process.stdout)
            print("Successfully retrieved subnet information:")
            print(json.dumps(subnets_data, indent=2))
        except json.JSONDecodeError:
            print("Error: Could not decode JSON output.")
            print(f"Raw output:\n{subnets_process.stdout}")
    else:
        print(f"Error running btcli subnets list:\n{subnets_process.stderr}")

except FileNotFoundError:
    print("Error: 'btcli' command not found. Ensure bittensor-cli is installed and in your PATH.")
except subprocess.CalledProcessError as e:
    print(f"An unexpected error occurred: {e}")
    print(f"Stdout: {e.stdout}")
    print(f"Stderr: {e.stderr}")

view raw JSON →