Subtensor API Python package
A python wrapper around the @polkadot/api node library to query the bittensor chain.
Install from pypi
pip install subtensorapi==1.1.0
Running the CLI
Usage
View usage
python3 -m subtensorapi --help
Specify chain endpoint url
python3 -m subtensorapi [sync_and_save|blockAtReg_and_save|sync_and_save_historical|sync_and_save_historical_difficulty] --endpoint_url ENDPOINT_URL
Specify filename to save to
python3 -m subtensorapi [sync_and_save|blockAtReg_and_save|sync_and_save_historical|sync_and_save_historical_difficulty] --filename FILENAME.json
Specify blockhash to sync the chain at, default "latest"
python3 -m subtensorapi [sync_and_save|blockAtReg_and_save|sync_and_save_historical|sync_and_save_historical_difficulty] --block_hash BLOCK_HASH
Sync And Save Metagraph
Pulls the neurons storage map and saves it to a JSON file.
View usage
python3 -m subtensorapi sync_and_save --help
Run sync of metagraph and save to JSON file
python3 -m subtensorapi sync_and_save -f metagraph.json
Sync And Save Neurons from Metagraph at historical blocks
Pulls the neurons storage map at each block for each UID and saves it to a JSON file.
View usage
python3 -m subtensorapi sync_and_save_historical --help
Run sync of metagraph at blocks 2706651 2706652 2706653 and UIDs 1 2 3 and save to JSON file
python3 -m subtensorapi sync_and_save_historical -i 1 2 3 -b 2706651 2706652 2706653 -f history.json
Grab blockAtRegistration
Pulls the blockAtRegistration storage map and saves it to a JSON file.
View usage
python3 -m subtensorapi blockAtReg_and_save --help
Sync And Save Difficulty at historical blocks
Pulls the difficulty storage value at each block and saves it to a JSON file.
View usage
python3 -m subtensorapi sync_and_save_historical_difficulty --help
Run sync of metagraph at blocks 2706651 2706652 2706653 and save to JSON file
python3 -m subtensorapi sync_and_save_historical_difficulty -b 2706651 2706652 2706653 -f history_diff.json
Using the library
FastSync class
Setup of a FastSync instance
from subtensorapi import FastSync
# check if fast sync is available on the platform
FastSync.verify_fast_sync_support()
# specify the chain endpoint_url
fast_sync: FastSync = FastSync(endpoint_url)
Run the metagraph sync
Pulls the neurons storage map.
# specify block_hash to sync at. Default is "latest"
block_hash = "0xb2fa081[...]"
# run the sync command and save to JSON file at block_hash
fast_sync.sync_and_save(block_hash)
# load neurons in from JSON file
neurons = fast_sync.load_neurons()
Run the historical metagraph sync
Pulls the neurons storage map for each block and each UID
# specify blockNumbers to sync at. Default is "latest"
blockNumbers = ["latest", 2706652]
# specify UIDs to sync
UIDs = [1, 2, 3, 4095]
# run the sync command and save to JSON file at block_hash
fast_sync.sync_and_save_historical(blockNumbers, UIDs)
# load neurons in from JSON file
historical_neurons = fast_sync.load_historical_neurons()
Run the historical difficulty sync
Pulls the difficulty storage value for each block
# specify blockNumbers to sync at. Default is "latest"
blockNumbers = ["latest", 2706652]
# run the sync command and save to JSON file at block_hash
fast_sync.sync_and_save_historical_difficulty(blockNumbers)
# load neurons in from JSON file
historical_diff = fast_sync.load_historical_difficulty()
Run blockAtRegistration pull
Pulls the blockAtRegistration storage map.
# specify block_hash to sync at. Default is "latest"
block_hash = "0xb2fa081[...]"
# run the pull command and save to JSON file at block_hash
fast_sync.get_blockAtRegistration_for_all_and_save(block_hash)
# load blockAtRegistration_all from JSON file
blockAtRegistration_all = fast_sync.load_blockAtRegistration_for_all()
Using the FastSync class without writing to a file
You can redirect the file writing to a pipe instead of a file.
This removes the need to write to disk and provides a speedup.
Example:
# all neurons
all_neurons: List[SimpleNamespace] = fast_sync.sync_fd(block_hash)
# historical neurons
historical_neurons: Dict[str, Dict[str, SimpleNamespace]] = fast_sync.sync_historical_fd(blockNumbers, UIDs)
# blockAtRegistration_all
blockAtRegistration_all: List[int] = fast_sync.get_blockAtRegistration_for_all_fd(block_hash)
# historical difficulty
historical_diff: Dict[str, int] = fast_sync.sync_historical_difficulty_fd(blockNumbers)
Metadata
Release files for subtensorapi 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subtensorapi-1.1.0-py3-none-manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details for subtensorapi-1.1.0-py3-none-manylinux_2_17_x86_64.whl |
| subtensorapi-1.1.0-py3-none-macosx_10_15_universal2.whl | Python 3 | none | macOS 10.15+ universal2 (ARM64, x86-64) | Details for subtensorapi-1.1.0-py3-none-macosx_10_15_universal2.whl |
Total release size: 42.8 MB
Release files / subtensorapi-1.1.0-py3-none-manylinux_2_17_x86_64.whl
| Download URL | subtensorapi-1.1.0-py3-none-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 21.4 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
8957895956f23bec21385d025be7601b6400b5e51b983a96fc11ebeb0f381094
|
|
BLAKE2b-256 checksum How to use checksums |
719accf9a9ca9abcc0ac539c18f631c59d89bb5ec906c12b14540368e95adf09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Release files / subtensorapi-1.1.0-py3-none-macosx_10_15_universal2.whl
| Download URL | subtensorapi-1.1.0-py3-none-macosx_10_15_universal2.whl |
|---|---|
| Size | 21.4 MB |
| Tags | Python 3 macOS 10.15+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
6a2c8826e4e54eb334b0201b9af404ab08605e31fda0c999fd1999c138bbcbdd
|
|
BLAKE2b-256 checksum How to use checksums |
c176d274d9a1cfcaa82c6b71ee9cbf61de9b5174da037c378b794621fd01ef46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Security for subtensorapi 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.