bittensor-pylon-client 2.3.1__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/PKG-INFO +1 -1
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/asynchronous/api.py +14 -5
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/sync/api.py +14 -5
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/translators.py +14 -2
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/abstract_async.py +64 -14
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/abstract_sync.py +58 -14
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/requests.py +3 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/exceptions.py +7 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/models.py +2 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/artanis/__init__.py +1 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/v1/__init__.py +1 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/.gitignore +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/_unstable/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/asynchronous/api.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/sync/api.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/v1/translators.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/asynchronous/client.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/asynchronous/communicators.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/asynchronous/config.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/config.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/namespace.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/neuron_client.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/sync/client.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/sync/communicators.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/client/sync/config.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/docker_manager.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/file_backed_neurons.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/bodies.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/endpoints.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/models.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/_unstable/responses.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/apiver.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/constants.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/currency.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/endpoints.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/settings.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/timeout.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/types/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/types/bittensor.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/types/evm.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/__init__.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/bodies.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/endpoints.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/models.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/requests.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/pylon_commons/v1/responses.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/translators.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/artanis/unstable.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/artanis/v1.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/exceptions.py +0 -0
- {bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bittensor-pylon-client
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Bittensor Pylon client library
|
|
5
5
|
Project-URL: homepage, https://github.com/backend-developers-ltd/bittensor-pylon
|
|
6
6
|
Project-URL: repository, https://github.com/backend-developers-ltd/bittensor-pylon
|
|
@@ -51,14 +51,19 @@ from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
|
51
51
|
class AsyncOpenAccessApi(AbstractAsyncOpenAccessApi):
|
|
52
52
|
api_version = ApiVersion.UNSTABLE
|
|
53
53
|
|
|
54
|
-
async def _get_neurons_request(
|
|
54
|
+
async def _get_neurons_request(
|
|
55
|
+
self, netuid: NetUid, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
56
|
+
) -> GetNeuronsRequest:
|
|
55
57
|
return GetNeuronsRequest(
|
|
56
58
|
netuid=netuid,
|
|
57
59
|
block_number=block_number,
|
|
60
|
+
mechanism_id=mechanism_id,
|
|
58
61
|
)
|
|
59
62
|
|
|
60
|
-
async def _get_latest_neurons_request(
|
|
61
|
-
|
|
63
|
+
async def _get_latest_neurons_request(
|
|
64
|
+
self, netuid: NetUid, mechanism_id: MechanismId = MechanismId(0)
|
|
65
|
+
) -> GetLatestNeuronsRequest:
|
|
66
|
+
return GetLatestNeuronsRequest(netuid=netuid, mechanism_id=mechanism_id)
|
|
62
67
|
|
|
63
68
|
async def _get_recent_neurons_request(self, netuid: NetUid) -> GetRecentNeuronsRequest:
|
|
64
69
|
return GetRecentNeuronsRequest(netuid=netuid)
|
|
@@ -134,17 +139,21 @@ class AsyncIdentityApi(AbstractAsyncIdentityApi):
|
|
|
134
139
|
raise PylonMisconfigured(f"Identity '{self.identity_name}' is not configured on the server.")
|
|
135
140
|
self._netuid = response.identities[self.identity_name]
|
|
136
141
|
|
|
137
|
-
async def _get_neurons_request(
|
|
142
|
+
async def _get_neurons_request(
|
|
143
|
+
self, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
144
|
+
) -> GetNeuronsRequest:
|
|
138
145
|
return GetNeuronsRequest(
|
|
139
146
|
netuid=self.netuid,
|
|
140
147
|
identity_name=self.identity_name,
|
|
141
148
|
block_number=block_number,
|
|
149
|
+
mechanism_id=mechanism_id,
|
|
142
150
|
)
|
|
143
151
|
|
|
144
|
-
async def _get_latest_neurons_request(self) -> GetLatestNeuronsRequest:
|
|
152
|
+
async def _get_latest_neurons_request(self, mechanism_id: MechanismId = MechanismId(0)) -> GetLatestNeuronsRequest:
|
|
145
153
|
return GetLatestNeuronsRequest(
|
|
146
154
|
netuid=self.netuid,
|
|
147
155
|
identity_name=self.identity_name,
|
|
156
|
+
mechanism_id=mechanism_id,
|
|
148
157
|
)
|
|
149
158
|
|
|
150
159
|
async def _get_recent_neurons_request(self) -> GetRecentNeuronsRequest:
|
|
@@ -51,14 +51,19 @@ from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
|
51
51
|
class OpenAccessApi(AbstractOpenAccessApi):
|
|
52
52
|
api_version = ApiVersion.UNSTABLE
|
|
53
53
|
|
|
54
|
-
def _get_neurons_request(
|
|
54
|
+
def _get_neurons_request(
|
|
55
|
+
self, netuid: NetUid, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
56
|
+
) -> GetNeuronsRequest:
|
|
55
57
|
return GetNeuronsRequest(
|
|
56
58
|
netuid=netuid,
|
|
57
59
|
block_number=block_number,
|
|
60
|
+
mechanism_id=mechanism_id,
|
|
58
61
|
)
|
|
59
62
|
|
|
60
|
-
def _get_latest_neurons_request(
|
|
61
|
-
|
|
63
|
+
def _get_latest_neurons_request(
|
|
64
|
+
self, netuid: NetUid, mechanism_id: MechanismId = MechanismId(0)
|
|
65
|
+
) -> GetLatestNeuronsRequest:
|
|
66
|
+
return GetLatestNeuronsRequest(netuid=netuid, mechanism_id=mechanism_id)
|
|
62
67
|
|
|
63
68
|
def _get_recent_neurons_request(self, netuid: NetUid) -> GetRecentNeuronsRequest:
|
|
64
69
|
return GetRecentNeuronsRequest(netuid=netuid)
|
|
@@ -132,17 +137,21 @@ class IdentityApi(AbstractIdentityApi):
|
|
|
132
137
|
raise PylonMisconfigured(f"Identity '{self.identity_name}' is not configured on the server.")
|
|
133
138
|
self._netuid = response.identities[self.identity_name]
|
|
134
139
|
|
|
135
|
-
def _get_neurons_request(
|
|
140
|
+
def _get_neurons_request(
|
|
141
|
+
self, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
142
|
+
) -> GetNeuronsRequest:
|
|
136
143
|
return GetNeuronsRequest(
|
|
137
144
|
netuid=self.netuid,
|
|
138
145
|
identity_name=self.identity_name,
|
|
139
146
|
block_number=block_number,
|
|
147
|
+
mechanism_id=mechanism_id,
|
|
140
148
|
)
|
|
141
149
|
|
|
142
|
-
def _get_latest_neurons_request(self) -> GetLatestNeuronsRequest:
|
|
150
|
+
def _get_latest_neurons_request(self, mechanism_id: MechanismId = MechanismId(0)) -> GetLatestNeuronsRequest:
|
|
143
151
|
return GetLatestNeuronsRequest(
|
|
144
152
|
netuid=self.netuid,
|
|
145
153
|
identity_name=self.identity_name,
|
|
154
|
+
mechanism_id=mechanism_id,
|
|
146
155
|
)
|
|
147
156
|
|
|
148
157
|
def _get_recent_neurons_request(self) -> GetRecentNeuronsRequest:
|
|
@@ -45,6 +45,13 @@ if TYPE_CHECKING:
|
|
|
45
45
|
HttpCommunicatorT = TypeVar("HttpCommunicatorT", bound="HttpCommunicator | AsyncHttpCommunicator")
|
|
46
46
|
|
|
47
47
|
|
|
48
|
+
def _mechanism_params(request: GetNeuronsRequest | GetLatestNeuronsRequest) -> dict[str, int] | None:
|
|
49
|
+
"""
|
|
50
|
+
Omit the default so requests stay identical for services without mechanism support.
|
|
51
|
+
"""
|
|
52
|
+
return {"mechanism_id": request.mechanism_id} if request.mechanism_id else None
|
|
53
|
+
|
|
54
|
+
|
|
48
55
|
class HttpTranslator(AbstractRequestTranslator[Request, HttpCommunicatorT]):
|
|
49
56
|
"""
|
|
50
57
|
Translates PylonRequests into httpx Requests using _unstable API endpoints.
|
|
@@ -75,7 +82,9 @@ class HttpTranslator(AbstractRequestTranslator[Request, HttpCommunicatorT]):
|
|
|
75
82
|
def _translate_get_neurons(self, request: GetNeuronsRequest, communicator: HttpCommunicatorT) -> Request:
|
|
76
83
|
url = self._build_url(self._endpoint_cls.NEURONS, request)
|
|
77
84
|
headers = self._get_auth_headers(request, communicator)
|
|
78
|
-
return communicator.raw_client.build_request(
|
|
85
|
+
return communicator.raw_client.build_request(
|
|
86
|
+
method=self._endpoint_cls.NEURONS.method, url=url, headers=headers, params=_mechanism_params(request)
|
|
87
|
+
)
|
|
79
88
|
|
|
80
89
|
def _translate_get_latest_neurons(
|
|
81
90
|
self, request: GetLatestNeuronsRequest, communicator: HttpCommunicatorT
|
|
@@ -83,7 +92,10 @@ class HttpTranslator(AbstractRequestTranslator[Request, HttpCommunicatorT]):
|
|
|
83
92
|
url = self._build_url(self._endpoint_cls.LATEST_NEURONS, request)
|
|
84
93
|
headers = self._get_auth_headers(request, communicator)
|
|
85
94
|
return communicator.raw_client.build_request(
|
|
86
|
-
method=self._endpoint_cls.LATEST_NEURONS.method,
|
|
95
|
+
method=self._endpoint_cls.LATEST_NEURONS.method,
|
|
96
|
+
url=url,
|
|
97
|
+
headers=headers,
|
|
98
|
+
params=_mechanism_params(request),
|
|
87
99
|
)
|
|
88
100
|
|
|
89
101
|
def _translate_get_recent_neurons(
|
|
@@ -58,6 +58,7 @@ from pylon_client._internal.pylon_commons._unstable.responses import (
|
|
|
58
58
|
from pylon_client._internal.pylon_commons.apiver import ApiVersion
|
|
59
59
|
from pylon_client._internal.pylon_commons.exceptions import (
|
|
60
60
|
PylonClosed,
|
|
61
|
+
PylonMechanismMismatch,
|
|
61
62
|
PylonNetuidMismatch,
|
|
62
63
|
)
|
|
63
64
|
from pylon_client._internal.pylon_commons.types import (
|
|
@@ -99,6 +100,15 @@ class AbstractAsyncApi(ABC):
|
|
|
99
100
|
request.api_version = self.api_version
|
|
100
101
|
return await self._communicator.request(request)
|
|
101
102
|
|
|
103
|
+
@staticmethod
|
|
104
|
+
def _require_mechanism(response: GetNeuronsResponse, mechanism_id: MechanismId) -> GetNeuronsResponse:
|
|
105
|
+
if response.mechanism_id != mechanism_id:
|
|
106
|
+
raise PylonMechanismMismatch(
|
|
107
|
+
f"Requested mechanism {mechanism_id} but the service answered for mechanism {response.mechanism_id}; "
|
|
108
|
+
"upgrade the Pylon service"
|
|
109
|
+
)
|
|
110
|
+
return response
|
|
111
|
+
|
|
102
112
|
def _file_backed_neurons(self) -> GetNeuronsResponse | None:
|
|
103
113
|
"""
|
|
104
114
|
Returns neurons loaded from the configured local `neurons_file` for local development,
|
|
@@ -127,33 +137,47 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
127
137
|
|
|
128
138
|
# Public API
|
|
129
139
|
|
|
130
|
-
async def get_neurons(
|
|
140
|
+
async def get_neurons(
|
|
141
|
+
self, netuid: NetUid, block_number: BlockNumber, *, mechanism_id: MechanismId = MechanismId(0)
|
|
142
|
+
) -> GetNeuronsResponse:
|
|
131
143
|
"""
|
|
132
144
|
Retrieves neurons for a specific subnet at a given block number.
|
|
133
145
|
|
|
134
146
|
Args:
|
|
135
147
|
netuid: The unique identifier of the subnet.
|
|
136
148
|
block_number: The blockchain block number to query neurons at.
|
|
149
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
137
150
|
|
|
138
151
|
Returns:
|
|
139
152
|
GetNeuronsResponse: containing the block information and a dictionary mapping hotkeys to Neuron objects.
|
|
153
|
+
|
|
154
|
+
Raises:
|
|
155
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
140
156
|
"""
|
|
141
|
-
|
|
157
|
+
response = await self._send_request(await self._get_neurons_request(netuid, block_number, mechanism_id))
|
|
158
|
+
return self._require_mechanism(response, mechanism_id)
|
|
142
159
|
|
|
143
|
-
async def get_latest_neurons(
|
|
160
|
+
async def get_latest_neurons(
|
|
161
|
+
self, netuid: NetUid, *, mechanism_id: MechanismId = MechanismId(0)
|
|
162
|
+
) -> GetNeuronsResponse:
|
|
144
163
|
"""
|
|
145
164
|
Retrieves neurons for a specific subnet at the latest available block.
|
|
146
165
|
|
|
147
166
|
Args:
|
|
148
167
|
netuid: The unique identifier of the subnet.
|
|
168
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
149
169
|
|
|
150
170
|
Returns:
|
|
151
171
|
GetNeuronsResponse: containing the latest block information and a dictionary mapping hotkeys to
|
|
152
172
|
Neuron objects.
|
|
173
|
+
|
|
174
|
+
Raises:
|
|
175
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
153
176
|
"""
|
|
154
|
-
if (file_backed := self._file_backed_neurons()) is not None:
|
|
177
|
+
if mechanism_id == 0 and (file_backed := self._file_backed_neurons()) is not None:
|
|
155
178
|
return file_backed
|
|
156
|
-
|
|
179
|
+
response = await self._send_request(await self._get_latest_neurons_request(netuid, mechanism_id))
|
|
180
|
+
return self._require_mechanism(response, mechanism_id)
|
|
157
181
|
|
|
158
182
|
async def get_recent_neurons(self, netuid: NetUid) -> GetNeuronsResponse:
|
|
159
183
|
"""
|
|
@@ -375,10 +399,14 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
375
399
|
# Private API
|
|
376
400
|
|
|
377
401
|
@abstractmethod
|
|
378
|
-
async def _get_neurons_request(
|
|
402
|
+
async def _get_neurons_request(
|
|
403
|
+
self, netuid: NetUid, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
404
|
+
) -> GetNeuronsRequest: ...
|
|
379
405
|
|
|
380
406
|
@abstractmethod
|
|
381
|
-
async def _get_latest_neurons_request(
|
|
407
|
+
async def _get_latest_neurons_request(
|
|
408
|
+
self, netuid: NetUid, mechanism_id: MechanismId = MechanismId(0)
|
|
409
|
+
) -> GetLatestNeuronsRequest: ...
|
|
382
410
|
|
|
383
411
|
@abstractmethod
|
|
384
412
|
async def _get_recent_neurons_request(self, netuid: NetUid) -> GetRecentNeuronsRequest: ...
|
|
@@ -508,29 +536,47 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
508
536
|
|
|
509
537
|
# Public API
|
|
510
538
|
|
|
511
|
-
async def get_neurons(
|
|
539
|
+
async def get_neurons(
|
|
540
|
+
self, block_number: BlockNumber, *, mechanism_id: MechanismId = MechanismId(0)
|
|
541
|
+
) -> GetNeuronsResponse:
|
|
512
542
|
"""
|
|
513
543
|
Retrieves neurons for the authenticated identity's subnet at a given block number.
|
|
514
544
|
|
|
515
545
|
Args:
|
|
516
546
|
block_number: The blockchain block number to query neurons at.
|
|
547
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
517
548
|
|
|
518
549
|
Returns:
|
|
519
550
|
GetNeuronsResponse containing the block information and a dictionary mapping hotkeys to Neuron objects.
|
|
551
|
+
|
|
552
|
+
Raises:
|
|
553
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
520
554
|
"""
|
|
521
|
-
|
|
555
|
+
response = await self._send_identity_request(
|
|
556
|
+
partial(self._get_neurons_request, block_number, mechanism_id=mechanism_id)
|
|
557
|
+
)
|
|
558
|
+
return self._require_mechanism(response, mechanism_id)
|
|
522
559
|
|
|
523
|
-
async def get_latest_neurons(self) -> GetNeuronsResponse:
|
|
560
|
+
async def get_latest_neurons(self, *, mechanism_id: MechanismId = MechanismId(0)) -> GetNeuronsResponse:
|
|
524
561
|
"""
|
|
525
562
|
Retrieves neurons for the authenticated identity's subnet at the latest available block.
|
|
526
563
|
|
|
564
|
+
Args:
|
|
565
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
566
|
+
|
|
527
567
|
Returns:
|
|
528
568
|
GetNeuronsResponse containing the latest block information and a dictionary mapping hotkeys to
|
|
529
569
|
Neuron objects.
|
|
570
|
+
|
|
571
|
+
Raises:
|
|
572
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
530
573
|
"""
|
|
531
|
-
if (file_backed := self._file_backed_neurons()) is not None:
|
|
574
|
+
if mechanism_id == 0 and (file_backed := self._file_backed_neurons()) is not None:
|
|
532
575
|
return file_backed
|
|
533
|
-
|
|
576
|
+
response = await self._send_identity_request(
|
|
577
|
+
partial(self._get_latest_neurons_request, mechanism_id=mechanism_id)
|
|
578
|
+
)
|
|
579
|
+
return self._require_mechanism(response, mechanism_id)
|
|
534
580
|
|
|
535
581
|
async def get_recent_neurons(self) -> GetNeuronsResponse:
|
|
536
582
|
"""
|
|
@@ -793,10 +839,14 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
793
839
|
# Private API
|
|
794
840
|
|
|
795
841
|
@abstractmethod
|
|
796
|
-
async def _get_neurons_request(
|
|
842
|
+
async def _get_neurons_request(
|
|
843
|
+
self, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
844
|
+
) -> GetNeuronsRequest: ...
|
|
797
845
|
|
|
798
846
|
@abstractmethod
|
|
799
|
-
async def _get_latest_neurons_request(
|
|
847
|
+
async def _get_latest_neurons_request(
|
|
848
|
+
self, mechanism_id: MechanismId = MechanismId(0)
|
|
849
|
+
) -> GetLatestNeuronsRequest: ...
|
|
800
850
|
|
|
801
851
|
@abstractmethod
|
|
802
852
|
async def _get_recent_neurons_request(self) -> GetRecentNeuronsRequest: ...
|
|
@@ -58,6 +58,7 @@ from pylon_client._internal.pylon_commons._unstable.responses import (
|
|
|
58
58
|
from pylon_client._internal.pylon_commons.apiver import ApiVersion
|
|
59
59
|
from pylon_client._internal.pylon_commons.exceptions import (
|
|
60
60
|
PylonClosed,
|
|
61
|
+
PylonMechanismMismatch,
|
|
61
62
|
PylonNetuidMismatch,
|
|
62
63
|
)
|
|
63
64
|
from pylon_client._internal.pylon_commons.types import (
|
|
@@ -99,6 +100,15 @@ class AbstractApi(ABC):
|
|
|
99
100
|
request.api_version = self.api_version
|
|
100
101
|
return self._communicator.request(request)
|
|
101
102
|
|
|
103
|
+
@staticmethod
|
|
104
|
+
def _require_mechanism(response: GetNeuronsResponse, mechanism_id: MechanismId) -> GetNeuronsResponse:
|
|
105
|
+
if response.mechanism_id != mechanism_id:
|
|
106
|
+
raise PylonMechanismMismatch(
|
|
107
|
+
f"Requested mechanism {mechanism_id} but the service answered for mechanism {response.mechanism_id}; "
|
|
108
|
+
"upgrade the Pylon service"
|
|
109
|
+
)
|
|
110
|
+
return response
|
|
111
|
+
|
|
102
112
|
def _file_backed_neurons(self) -> GetNeuronsResponse | None:
|
|
103
113
|
"""
|
|
104
114
|
Returns neurons loaded from the configured local `neurons_file` for local development,
|
|
@@ -127,33 +137,45 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
127
137
|
|
|
128
138
|
# Public API
|
|
129
139
|
|
|
130
|
-
def get_neurons(
|
|
140
|
+
def get_neurons(
|
|
141
|
+
self, netuid: NetUid, block_number: BlockNumber, *, mechanism_id: MechanismId = MechanismId(0)
|
|
142
|
+
) -> GetNeuronsResponse:
|
|
131
143
|
"""
|
|
132
144
|
Retrieves neurons for a specific subnet at a given block number.
|
|
133
145
|
|
|
134
146
|
Args:
|
|
135
147
|
netuid: The unique identifier of the subnet.
|
|
136
148
|
block_number: The blockchain block number to query neurons at.
|
|
149
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
137
150
|
|
|
138
151
|
Returns:
|
|
139
152
|
GetNeuronsResponse: containing the block information and a dictionary mapping hotkeys to Neuron objects.
|
|
153
|
+
|
|
154
|
+
Raises:
|
|
155
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
140
156
|
"""
|
|
141
|
-
|
|
157
|
+
response = self._send_request(self._get_neurons_request(netuid, block_number, mechanism_id))
|
|
158
|
+
return self._require_mechanism(response, mechanism_id)
|
|
142
159
|
|
|
143
|
-
def get_latest_neurons(self, netuid: NetUid) -> GetNeuronsResponse:
|
|
160
|
+
def get_latest_neurons(self, netuid: NetUid, *, mechanism_id: MechanismId = MechanismId(0)) -> GetNeuronsResponse:
|
|
144
161
|
"""
|
|
145
162
|
Retrieves neurons for a specific subnet at the latest available block.
|
|
146
163
|
|
|
147
164
|
Args:
|
|
148
165
|
netuid: The unique identifier of the subnet.
|
|
166
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
149
167
|
|
|
150
168
|
Returns:
|
|
151
169
|
GetNeuronsResponse: containing the latest block information and a dictionary mapping hotkeys to
|
|
152
170
|
Neuron objects.
|
|
171
|
+
|
|
172
|
+
Raises:
|
|
173
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
153
174
|
"""
|
|
154
|
-
if (file_backed := self._file_backed_neurons()) is not None:
|
|
175
|
+
if mechanism_id == 0 and (file_backed := self._file_backed_neurons()) is not None:
|
|
155
176
|
return file_backed
|
|
156
|
-
|
|
177
|
+
response = self._send_request(self._get_latest_neurons_request(netuid, mechanism_id))
|
|
178
|
+
return self._require_mechanism(response, mechanism_id)
|
|
157
179
|
|
|
158
180
|
def get_recent_neurons(self, netuid: NetUid) -> GetNeuronsResponse:
|
|
159
181
|
"""
|
|
@@ -374,10 +396,14 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
374
396
|
# Private API
|
|
375
397
|
|
|
376
398
|
@abstractmethod
|
|
377
|
-
def _get_neurons_request(
|
|
399
|
+
def _get_neurons_request(
|
|
400
|
+
self, netuid: NetUid, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
401
|
+
) -> GetNeuronsRequest: ...
|
|
378
402
|
|
|
379
403
|
@abstractmethod
|
|
380
|
-
def _get_latest_neurons_request(
|
|
404
|
+
def _get_latest_neurons_request(
|
|
405
|
+
self, netuid: NetUid, mechanism_id: MechanismId = MechanismId(0)
|
|
406
|
+
) -> GetLatestNeuronsRequest: ...
|
|
381
407
|
|
|
382
408
|
@abstractmethod
|
|
383
409
|
def _get_recent_neurons_request(self, netuid: NetUid) -> GetRecentNeuronsRequest: ...
|
|
@@ -503,29 +529,45 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
503
529
|
|
|
504
530
|
# Public API
|
|
505
531
|
|
|
506
|
-
def get_neurons(
|
|
532
|
+
def get_neurons(
|
|
533
|
+
self, block_number: BlockNumber, *, mechanism_id: MechanismId = MechanismId(0)
|
|
534
|
+
) -> GetNeuronsResponse:
|
|
507
535
|
"""
|
|
508
536
|
Retrieves neurons for the authenticated identity's subnet at a given block number.
|
|
509
537
|
|
|
510
538
|
Args:
|
|
511
539
|
block_number: The blockchain block number to query neurons at.
|
|
540
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
512
541
|
|
|
513
542
|
Returns:
|
|
514
543
|
GetNeuronsResponse containing the block information and a dictionary mapping hotkeys to Neuron objects.
|
|
544
|
+
|
|
545
|
+
Raises:
|
|
546
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
515
547
|
"""
|
|
516
|
-
|
|
548
|
+
response = self._send_identity_request(
|
|
549
|
+
partial(self._get_neurons_request, block_number, mechanism_id=mechanism_id)
|
|
550
|
+
)
|
|
551
|
+
return self._require_mechanism(response, mechanism_id)
|
|
517
552
|
|
|
518
|
-
def get_latest_neurons(self) -> GetNeuronsResponse:
|
|
553
|
+
def get_latest_neurons(self, *, mechanism_id: MechanismId = MechanismId(0)) -> GetNeuronsResponse:
|
|
519
554
|
"""
|
|
520
555
|
Retrieves neurons for the authenticated identity's subnet at the latest available block.
|
|
521
556
|
|
|
557
|
+
Args:
|
|
558
|
+
mechanism_id: Mechanism whose incentive and last update to return; other fields are subnet-wide.
|
|
559
|
+
|
|
522
560
|
Returns:
|
|
523
561
|
GetNeuronsResponse containing the latest block information and a dictionary mapping hotkeys to
|
|
524
562
|
Neuron objects.
|
|
563
|
+
|
|
564
|
+
Raises:
|
|
565
|
+
PylonMechanismMismatch: The service answered for a different mechanism.
|
|
525
566
|
"""
|
|
526
|
-
if (file_backed := self._file_backed_neurons()) is not None:
|
|
567
|
+
if mechanism_id == 0 and (file_backed := self._file_backed_neurons()) is not None:
|
|
527
568
|
return file_backed
|
|
528
|
-
|
|
569
|
+
response = self._send_identity_request(partial(self._get_latest_neurons_request, mechanism_id=mechanism_id))
|
|
570
|
+
return self._require_mechanism(response, mechanism_id)
|
|
529
571
|
|
|
530
572
|
def get_recent_neurons(self) -> GetNeuronsResponse:
|
|
531
573
|
"""
|
|
@@ -792,10 +834,12 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
792
834
|
# Private API
|
|
793
835
|
|
|
794
836
|
@abstractmethod
|
|
795
|
-
def _get_neurons_request(
|
|
837
|
+
def _get_neurons_request(
|
|
838
|
+
self, block_number: BlockNumber, mechanism_id: MechanismId = MechanismId(0)
|
|
839
|
+
) -> GetNeuronsRequest: ...
|
|
796
840
|
|
|
797
841
|
@abstractmethod
|
|
798
|
-
def _get_latest_neurons_request(self) -> GetLatestNeuronsRequest: ...
|
|
842
|
+
def _get_latest_neurons_request(self, mechanism_id: MechanismId = MechanismId(0)) -> GetLatestNeuronsRequest: ...
|
|
799
843
|
|
|
800
844
|
@abstractmethod
|
|
801
845
|
def _get_recent_neurons_request(self) -> GetRecentNeuronsRequest: ...
|
|
@@ -93,6 +93,7 @@ class GetNeuronsRequest(AuthenticatedPylonRequest[GetNeuronsResponse]):
|
|
|
93
93
|
response_cls = GetNeuronsResponse
|
|
94
94
|
|
|
95
95
|
block_number: BlockNumber
|
|
96
|
+
mechanism_id: MechanismId = MechanismId(0)
|
|
96
97
|
|
|
97
98
|
|
|
98
99
|
class GetLatestNeuronsRequest(AuthenticatedPylonRequest[GetNeuronsResponse]):
|
|
@@ -102,6 +103,8 @@ class GetLatestNeuronsRequest(AuthenticatedPylonRequest[GetNeuronsResponse]):
|
|
|
102
103
|
|
|
103
104
|
response_cls = GetNeuronsResponse
|
|
104
105
|
|
|
106
|
+
mechanism_id: MechanismId = MechanismId(0)
|
|
107
|
+
|
|
105
108
|
|
|
106
109
|
class GetRecentNeuronsRequest(AuthenticatedPylonRequest[GetNeuronsResponse]):
|
|
107
110
|
"""
|
|
@@ -126,5 +126,12 @@ class PylonMisconfigured(BasePylonException):
|
|
|
126
126
|
"""
|
|
127
127
|
|
|
128
128
|
|
|
129
|
+
class PylonMechanismMismatch(BasePylonException):
|
|
130
|
+
"""
|
|
131
|
+
Error raised when the service answers a neuron request for a different mechanism, e.g. a service without
|
|
132
|
+
mechanism support.
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
|
|
129
136
|
class PylonCacheException(BasePylonException):
|
|
130
137
|
"""Base class for all Pylon cache exception."""
|
|
@@ -24,6 +24,7 @@ from .types import (
|
|
|
24
24
|
Hotkey,
|
|
25
25
|
Incentive,
|
|
26
26
|
MaxWeightsLimit,
|
|
27
|
+
MechanismId,
|
|
27
28
|
NetUid,
|
|
28
29
|
NeuronActive,
|
|
29
30
|
NeuronUid,
|
|
@@ -134,6 +135,7 @@ class Neuron(BittensorModel):
|
|
|
134
135
|
|
|
135
136
|
class SubnetNeurons(BittensorModel):
|
|
136
137
|
block: Block
|
|
138
|
+
mechanism_id: MechanismId = MechanismId(0)
|
|
137
139
|
neurons: dict[Hotkey, Neuron]
|
|
138
140
|
|
|
139
141
|
|
|
File without changes
|
|
File without changes
|
{bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/__init__.py
RENAMED
|
File without changes
|
{bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/api/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/_internal/translators.py
RENAMED
|
File without changes
|
{bittensor_pylon_client-2.3.1 → bittensor_pylon_client-2.4.0}/pylon_client/artanis/unstable.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|