Skip to content

Commit 949df27

Browse files
MichaelTrestmanMichael Trestman
andauthored
update autogened api docs and add subtensor-api doc (#571)
* add subtensor-api doc * wip * chop unnecessary note --------- Co-authored-by: Michael Trestman <[email protected]>
1 parent cbfd230 commit 949df27

File tree

418 files changed

+44015
-26588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

418 files changed

+44015
-26588
lines changed

docs/_sphinx-gen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ When you are ready to publish the docs, proceed to the below next step.
2222
Publish the docs
2323

2424
To publish the docs on docs.bittensor.com, you will push the entire "build/html" directory into the docs repo. However, before you do that, remove the `html/_sources` directory. This directory contains reStructuredText source files and we don't want to version control them. So, do rm -r build/html/_sources first.
25-
In the docs repo, https://github.com/opentensor/developer-docs/tree/main , this "html" directory is located in the "developer-docs/static/python-api" path. Always replace the entire "html" directory even if you updated a single word or letter in a docstring.
25+
In the docs repo, https://github.com/opentensor/developer-docs/tree/main , this "html" directory is located in the "developer-docs/python-api" path. Always replace the entire "html" directory even if you updated a single word or letter in a docstring.
2626
In the Markdown file that contains links to these Python reference docs and sections, you will use "pathname:///python-api/html/index.html" for linking to the homepage of the Python ref docs. See "docs/bt-api-ref.md" for examples.
2727

2828
Conf.py

docs/bt-api-ref.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ import { SiTrpc } from "react-icons/si";
1818

1919
# Bittensor SDK
2020

21-
This section presents the Bittensor SDK reference documentation. Follow the below links to specific Python modules or [click here for SDK reference homepage](pathname:///python-api/autoapi/bittensor/index.html).
21+
This section presents the Bittensor SDK reference documentation. Follow the below links to specific Python modules or [click here for SDK reference homepage](pathname:///python-api/html/autoapi/bittensor/index.html).
2222

2323
<Cards>
2424
<Card
2525
icon={PiBrainFill}
2626
title='Subtensor'
27-
link='pathname:///python-api/autoapi/bittensor/core/subtensor/index.html'
27+
link='pathname:///python-api/html/autoapi/bittensor/core/subtensor/index.html'
2828
body='Subtensor class provides a gateway to the blockchain layer of Bittensor.' />
2929
<Card
3030
icon={GiHiveMind}
3131
title='Axon'
32-
link='pathname:///python-api/autoapi/bittensor/core/axon/index.html'
32+
link='pathname:///python-api/html/autoapi/bittensor/core/axon/index.html'
3333
body='Axon services the forward and backward requests from other neurons.' />
3434
<Card
3535
icon={GiOvermind}
3636
title='Dendrite'
37-
link='pathname:///python-api/autoapi/bittensor/core/dendrite/index.html'
37+
link='pathname:///python-api/html/autoapi/bittensor/core/dendrite/index.html'
3838
body='Dendrite represents the abstracted implementation of a network client module.' />
3939
<Card
4040
icon={SiTrpc}
4141
title='Extrinsics'
42-
link='pathname:///python-api/autoapi/bittensor/core/extrinsics/index.html'
42+
link='pathname:///python-api/html/autoapi/bittensor/core/extrinsics/index.html'
4343
body='Set weights, Axon serving, transfer, submit extrinsic, and more.' />
4444
<Card
4545
icon={GiBrainTentacle}
4646
title='Metagraph'
47-
link='pathname:///python-api/autoapi/bittensor/core/metagraph/index.html'
47+
link='pathname:///python-api/html/autoapi/bittensor/core/metagraph/index.html'
4848
body='Metagraph neural graph is a dynamic representation of the Bittensor network state.' />
4949
<Card
5050
icon={GiBrainStem}
5151
title='Synapse'
52-
link='pathname:///python-api/autoapi/bittensor/core/synapse/index.html'
52+
link='pathname:///python-api/html/autoapi/bittensor/core/synapse/index.html'
5353
body='Synapse module serves as a communication schema between neurons (nodes).' />
5454
</Cards>

docs/dynamic-tao/dtao-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Held stake (alpha tokens) may increase or decrease in TAO value as the price of
7171

7272
It is up to the subnet creator, and is configured using the `TransferToggle` hyperparameter.
7373

74-
When enabled, a holder of alpha stake can transfer its ownership to another coldkey/wallet using [`btcli stake transfer`](../staking-and-delegation/managing-stake-btcli#transferring-stake) or [`transfer_stake`](pathname:///python-api/autoapi/bittensor/core/async_subtensor/index.html#bittensor.core.async_subtensor.AsyncSubtensor.transfer_stake).
74+
When enabled, a holder of alpha stake can transfer its ownership to another coldkey/wallet using [`btcli stake transfer`](../staking-and-delegation/managing-stake-btcli#transferring-stake) or [`transfer_stake`](pathname:///python-api/html/autoapi/bittensor/core/async_subtensor/index.html#bittensor.core.async_subtensor.AsyncSubtensor.transfer_stake).
7575

7676
### How will Dynamic TAO affect governance of the network?
7777

docs/sdk/subtensor-api.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Subtensor API
3+
---
4+
5+
# Subtensor API
6+
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.
8+
9+
Reference docs: [SubtensorApi](pathname:///python-api/html/autoapi/bittensor/core/subtensor_api/index.html)
10+
11+
:::tip
12+
Upgrade to the [latest Bittensor release](https://pypi.org/project/bittensor/).
13+
```shell
14+
pip install bittensor
15+
```
16+
:::
17+
18+
## Basic Usage
19+
20+
### Synchronous Usage (Default)
21+
22+
```python
23+
import bittensor as bt
24+
25+
sub = bt.SubtensorApi()
26+
27+
print(sub.block) # Get current block number
28+
print(sub.delegates.get_delegate_identities())
29+
sub.chain.tx_rate_limit()
30+
```
31+
32+
### Asynchronous Usage
33+
34+
```python
35+
import bittensor as bt
36+
import asyncio
37+
38+
async def main():
39+
sub = bt.SubtensorApi(async_subtensor=True)
40+
async with sub:
41+
print(await sub.block)
42+
print(await sub.delegates.get_delegate_identities())
43+
await sub.chain.tx_rate_limit()
44+
45+
asyncio.run(main())
46+
```
47+
48+
## Legacy Method Support
49+
50+
You can enable all legacy methods from the original `Subtensor` class directly on this interface:
51+
52+
```python
53+
import bittensor as bt
54+
55+
sub = bt.SubtensorApi(legacy_methods=True)
56+
print(sub.bonds(0)) # Classic method usage
57+
```
58+
59+
## Retry and Fallback RPC Nodes
60+
61+
Enable redundancy and resilience with fallback chains and retry logic:
62+
63+
```python
64+
import bittensor as bt
65+
66+
sub = bt.SubtensorApi(
67+
"local",
68+
fallback_chains=[
69+
"wss://fallback1.taonetwork.com:9944",
70+
"wss://lite.sub.latent.to:443",
71+
],
72+
retry_forever=True,
73+
)
74+
print(sub.block)
75+
```
76+
77+
## Mock Mode for Testing
78+
79+
Use `mock=True` to simulate the interface without connecting to the blockchain:
80+
81+
```python
82+
import bittensor as bt
83+
84+
sub = bt.SubtensorApi(mock=True)
85+
print(sub) # Output: "<Network: None, Chain: Mock, Sync version>"
86+
```
87+
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
108+
109+
You can pass a pre-built `Config` object:
110+
111+
```python
112+
import argparse
113+
import bittensor as bt
114+
115+
parser = argparse.ArgumentParser('Miner')
116+
bt.SubtensorApi.add_args(parser)
117+
config = bt.config(parser)
118+
sub = bt.SubtensorApi(config=config)
119+
120+
print(sub)
121+
```
122+
123+
## Context Manager Usage
124+
125+
### Synchronous Context Manager
126+
127+
```python
128+
import bittensor as bt
129+
130+
with bt.SubtensorApi() as sub:
131+
print(sub.block)
132+
```
133+
134+
### Asynchronous Context Manager
135+
136+
```python
137+
import bittensor as bt
138+
import asyncio
139+
140+
async def main():
141+
async with bt.SubtensorApi(async_subtensor=True) as sub:
142+
print(await sub.block)
143+
144+
asyncio.run(main())
145+
```

docs/validators/index.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Validating is not supported on Windows.
2020

2121
## Requirements for validation
2222

23-
To have a **validator permit** in a given subnet, allowing you to submit miner evaluations using `btcli weights commit` or the SDK's [`set_weights`](pathname:///python-api/autoapi/bittensor/core/extrinsics/set_weights/index.html#module-bittensor.core.extrinsics.set_weights) function, you must meet the following requirements:
23+
To have a **validator permit** in a given subnet, allowing you to submit miner evaluations using `btcli weights commit` or the SDK's [`set_weights`](pathname:///python-api/html/autoapi/bittensor/core/extrinsics/set_weights/index.html#module-bittensor.core.extrinsics.set_weights) function, you must meet the following requirements:
2424

2525
- Your hotkey must be registered, granting you a UID on the subnet
2626
- You must have a stake-weight on the subnet of least 1000, including stake delegated to your hotkey from other wallets' coldkeys. A validator's stake weight in a subnet equals their alpha stake plus their TAO stake times the `tao_weight` parameter (current value: 0.18):
@@ -48,9 +48,6 @@ Add stake to your validator before registering:
4848
# Stake funds to your hotkey account within the subnet.
4949
btcli stake add --wallet.name <wallet name> --wallet.hotkey <your validating hotkey>
5050
```
51-
:::tip Root Subnet (Subnet 0) only
52-
In order to be able to set weights in a subnet, you will need a minimum of 1000 of stake weight in the subnet's alpha token. Stake weight is calculated as TAO * .18 + alpha: 1000 stake weight of alpha in a subnet could be 1000 alpha tokens staked, 18000 TAO staked, or a combination of the two such that the stake weight for the subnet is at least 1000.
53-
:::
5451

5552
## Validator registration
5653

sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ const sidebars = {
118118
collapsed: true,
119119
items: [
120120
"getting-started/installation",
121-
"bt-api-ref",
121+
"bt-api-ref",
122+
"sdk/subtensor-api",
122123
"getting-started/install-wallet-sdk",
123124
"migration_guide",
124125
"subnets/asyncio",

0 commit comments

Comments
 (0)