Skip to content

Commit 1302405

Browse files
MichaelTrestmanMichael Trestman
andauthored
polish up subtensor-api page (#573)
* polish up subtensor-api page * tweaks from review --------- Co-authored-by: Michael Trestman <[email protected]>
1 parent e25a39e commit 1302405

File tree

1 file changed

+55
-29
lines changed

1 file changed

+55
-29
lines changed

docs/sdk/subtensor-api.md

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,65 @@ title: Subtensor API
44

55
# Subtensor API
66

7-
The SubtensorApi is a high-level, unified interface to interact with the Bittensor blockchain. It wraps both the synchronous and asynchronous Subtensor implementations, providing modular access to chain subsystems like wallets, delegates, neurons, and more.
7+
8+
## Overview
9+
10+
The SubtensorApi is a unified interface for the Bittensor blockchain. It wraps both the synchronous and asynchronous Subtensor implementations, providing modular access to chain subsystems like wallets, delegates, neurons, and more.
11+
12+
13+
### Modules
14+
15+
All methods are grouped into logical modules for better organization and readability. Some methods may belong to more than one group if they span multiple functional areas. This does not compromise the internal logic — rather, it enhances discoverability and cohesion. Method equivalence between `SubtensorApi` and the original `Subtensor` is automatically verified by test coverage on every pull request (PR).
16+
17+
18+
<details>
19+
<summary>Subsystem modules</summary>
20+
21+
| Property | Description |
22+
|----------|-------------|
23+
| chain | Blockchain interaction methods |
24+
| commitments | Commitment and reveal logic |
25+
| delegates | Delegate management tools |
26+
| extrinsics | Transaction construction and signing |
27+
| metagraphs | Metagraph data and operations |
28+
| neurons | Neuron-level APIs |
29+
| queries | General query endpoints |
30+
| staking | Staking operations |
31+
| subnets | Subnet access and management |
32+
| wallets | Wallet creation, import/export |
33+
</details>
34+
35+
### Configuration
36+
37+
The behavior of the `SubtensorApi` object is configured with the following parameters.
38+
<details>
39+
<summary>Parameters</summary>
40+
41+
| Parameter | Type | Description | Default Value |
42+
|-------------------|-------------------|----------------------------------------------------------------------------------------------------------|-------------------------------|
43+
| `network` | `str` or `None` | The network to connect to. If not specified, defaults to `"finney"`. | `None` (interpreted as "finney")|
44+
| `config` | `Config` or `None`| Pre-built Bittensor configuration object. | `None` |
45+
| `async_subtensor` | `bool` | Whether to use the asynchronous version of the API. | `False` |
46+
| `legacy_methods` | `bool` | If `True`, all methods from the legacy `Subtensor` class are added to this class. | `False` |
47+
| `fallback_chains` | `list[str]` or `None`| List of fallback chains to use if the primary network is unavailable. | `None` |
48+
| `retry_forever` | `bool` | If `True`, continuously retries on connection errors until successful. | `False` |
49+
| `log_verbose` | `bool` | Enables detailed logging output when set to `True`. | `False` |
50+
| `mock` | `bool` | Enables mock mode for testing without connecting to the blockchain. | `False` |
51+
</details>
52+
853

954
Reference docs: [SubtensorApi](pathname:///python-api/html/autoapi/bittensor/core/subtensor_api/index.html)
1055

56+
## Basic Usage
57+
1158
:::tip
1259
Upgrade to the [latest Bittensor release](https://pypi.org/project/bittensor/).
1360
```shell
1461
pip install bittensor
1562
```
1663
:::
1764

18-
## Basic Usage
19-
20-
### Synchronous Usage (Default)
65+
### Synchronous (Default)
2166

2267
```python
2368
import bittensor as bt
@@ -29,7 +74,7 @@ print(sub.delegates.get_delegate_identities())
2974
sub.chain.tx_rate_limit()
3075
```
3176

32-
### Asynchronous Usage
77+
### Asynchronous
3378

3479
```python
3580
import bittensor as bt
@@ -44,8 +89,7 @@ async def main():
4489

4590
asyncio.run(main())
4691
```
47-
48-
## Legacy Method Support
92+
### Legacy Method Support
4993

5094
You can enable all legacy methods from the original `Subtensor` class directly on this interface:
5195

@@ -56,7 +100,8 @@ sub = bt.SubtensorApi(legacy_methods=True)
56100
print(sub.bonds(0)) # Classic method usage
57101
```
58102

59-
## Retry and Fallback RPC Nodes
103+
## Advanced Usage
104+
### Retry and Fallback RPC Nodes
60105

61106
Enable redundancy and resilience with fallback chains and retry logic:
62107

@@ -74,7 +119,7 @@ sub = bt.SubtensorApi(
74119
print(sub.block)
75120
```
76121

77-
## Mock Mode for Testing
122+
### Mock Mode for Testing
78123

79124
Use `mock=True` to simulate the interface without connecting to the blockchain:
80125

@@ -85,26 +130,7 @@ sub = bt.SubtensorApi(mock=True)
85130
print(sub) # Output: "<Network: None, Chain: Mock, Sync version>"
86131
```
87132

88-
## Subsystem Overview
89-
90-
All methods are grouped into logical modules for better organization and readability. Some methods may belong to more than one group if they span multiple functional areas. This does not compromise the internal logic — rather, it enhances discoverability and cohesion. Method equivalence between `SubtensorApi` and the original `Subtensor` is automatically verified by test coverage on every pull request (PR).
91-
92-
The following properties are modular access points for specialized subsystems:
93-
94-
| Property | Description |
95-
|----------|-------------|
96-
| chain | Blockchain interaction methods |
97-
| commitments | Commitment and reveal logic |
98-
| delegates | Delegate management tools |
99-
| extrinsics | Transaction construction and signing |
100-
| metagraphs | Metagraph data and operations |
101-
| neurons | Neuron-level APIs |
102-
| queries | General query endpoints |
103-
| stakes | Staking operations |
104-
| subnets | Subnet access and management |
105-
| wallets | Wallet creation, import/export |
106-
107-
## Custom Configuration Support
133+
### Custom Configuration
108134

109135
You can pass a pre-built `Config` object:
110136

0 commit comments

Comments
 (0)