gRPC client module¶
The gRPC client module provides infrastructure for communication with Akash providers using gRPC protocol. It handles SSL connections with self-signed certificates that providers typically use. This is primarily used internally by other modules but can be used directly for custom provider integrations.
ProviderGRPCClient Class¶
from akash import AkashClient
from akash.grpc_client import ProviderGRPCClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
grpc_client = ProviderGRPCClient(client)
result = grpc_client.get_provider_status(provider_address)
Constructor parameters¶
Parameter | Type | Default | Description |
---|---|---|---|
akash_client |
AkashClient |
Required | Parent AkashClient instance |
timeout |
int |
30 |
Default timeout for gRPC calls in seconds |
retries |
int |
3 |
Default number of retries for failed calls |
Provider status methods¶
get_provider_status()¶
Get provider status information via gRPC or REST API with automatic protocol selection.
def get_provider_status(
provider_address: str,
retries: Optional[int] = None,
timeout: Optional[int] = None,
insecure: bool = True,
check_version: bool = True
) -> Dict[str, Any]
Required parameters:
provider_address
(str
): Provider's blockchain address
Optional parameters:
retries
(int
): Number of retries (default: uses client default)timeout
(int
): Timeout in seconds (default: uses client default)insecure
(bool
): Skip SSL certificate verification for self-signed certificates (default: True)check_version
(bool
): Enable provider version checking for protocol selection (default: True)
Protocol selection:
- Checks provider version via REST
/version
endpoint ifcheck_version=True
- Uses REST
/status
endpoint for providers with version < 0.5.0 - Uses gRPC for providers with version >= 0.5.0 or when version check is disabled
- Tests multiple ports (8443, 8444) for gRPC connections
- Uses DNS pre-filtering to avoid invalid hostnames
- Bypasses SSL certificate verification to handle provider self-signed certificates
Returns: Dict[str, Any]
with the following fields:
status
(str
): Operation status ("success" or "error")response
(Dict
): Provider status data (if successful) with the following fields:cluster
(Dict
): Cluster status informationleases
(Dict
): Lease informationactive
(int
): Number of active leasesavailable
(int
): Number of available lease slots
inventory
(Dict
): Resource inventorycluster
(Dict
): Cluster resource informationnodes
(List[Dict]
): List of nodes with resourcesname
(str
): Node nameresources
(Dict
): Node resourcescpu
(Dict
): CPU resourcesunits
(str
): CPU units availableattributes
(List[Dict]
): CPU attributeskey
(str
): Attribute keyvalue
(str
): Attribute value
memory
(Dict
): Memory resourcesquantity
(str
): Memory quantity availableattributes
(List[Dict]
): Memory attributeskey
(str
): Attribute keyvalue
(str
): Attribute value
gpu
(Dict
): GPU resourcesunits
(str
): GPU units availableattributes
(List[Dict]
): GPU attributeskey
(str
): Attribute keyvalue
(str
): Attribute value
ephemeral_storage
(Dict
): Storage resourcesquantity
(str
): Storage quantity availableattributes
(List[Dict]
): Storage attributeskey
(str
): Attribute keyvalue
(str
): Attribute value
bid_engine
(Dict
): Bid engine statusorders
(int
): Number of orders processedavailable
(bool
): Whether bid engine is available
manifest
(Dict
): Manifest processing statusdeployments
(int
): Number of deployments processedavailable
(bool
): Whether manifest processing is available
errors
(List[str]
): Any error messagestimestamp
(str
): Status timestamp
attempts
(int
): Number of connection attempts madeerror
(str
): Error message (if failed)
Example:
from akash import AkashClient
from akash.grpc_client import ProviderGRPCClient
akash_client = AkashClient("https://akash-rpc.polkachu.com:443")
grpc_client = ProviderGRPCClient(akash_client)
result = grpc_client.get_provider_status(
provider_address="akash1provider123...",
timeout=10,
retries=2
)
if result["status"] == "success":
provider_data = result["response"]
print(f"Provider status retrieved in {result['attempts']} attempts")
print(f"Cluster leases: {provider_data.get('cluster', {}).get('leases', 0)}")
inventory = provider_data.get('cluster', {}).get('inventory', {})
print(f"Available resources: {inventory}")
else:
print(f"Failed to get provider status: {result['error']}")
print(f"Attempted {result['attempts']} times")
Management methods¶
cleanup_connections()¶
Clean up all active gRPC connections.
Returns: Dict[str, Any]
- Cleanup result with the following fields:
status
(str
): Cleanup status ("success" or "error")closed_channels
(int
): Number of gRPC channels closederror
(str
, optional): Error message if cleanup failed
Example:
from akash import AkashClient
from akash.grpc_client import ProviderGRPCClient
akash_client = AkashClient("https://akash-rpc.polkachu.com:443")
grpc_client = ProviderGRPCClient(akash_client)
result = grpc_client.cleanup_connections()
if result["status"] == "success":
print(f"Closed {result['closed_channels']} connections")
else:
print(f"Cleanup error: {result['error']}")
Context manager support¶
The ProviderGRPCClient
supports context manager usage for automatic cleanup.
from akash import AkashClient
from akash.grpc_client import ProviderGRPCClient
akash_client = AkashClient("https://akash-rpc.polkachu.com:443")
with ProviderGRPCClient(akash_client) as grpc_client:
result = grpc_client.get_provider_status("akash1provider123...")
Usage examples¶
Basic provider status query¶
from akash import AkashClient
from akash.grpc_client import ProviderGRPCClient
akash_client = AkashClient("https://akash-rpc.polkachu.com:443")
grpc_client = ProviderGRPCClient(akash_client, timeout=60, retries=5)
provider_address = "akash1provider123..."
try:
result = grpc_client.get_provider_status(
provider_address=provider_address,
timeout=30,
retries=3
)
if result["status"] == "success":
provider_data = result["response"]
print(f"Provider status retrieved successfully")
print(f"Attempts made: {result['attempts']}")
else:
print(f"Failed to get provider status: {result['error']}")
finally:
grpc_client.cleanup_connections()
Integration patterns¶
High-level module usage¶
Most users will not use ProviderGRPCClient
directly. Instead, it's used internally by other modules:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
# send_manifest uses gRPC via ProviderGRPCClient
result = client.manifest.send_manifest(
provider_endpoint=endpoint,
lease_id=lease_id,
manifest_groups=groups
)
# Provider status queries use gRPC
status = client.provider.get_provider_status("akash1provider123...")
Using with discovery module¶
The ProviderGRPCClient
is designed to work with the discovery module:
from akash import AkashClient
client = AkashClient("https://akash-rpc.polkachu.com:443")
provider_addresses = [
"akash1provider123...",
"akash1provider456..."
]
for provider_address in provider_addresses:
result = client.discovery.get_provider_status(provider_address)
if result["status"] == "success":
provider_status = result["provider_status"]
method = provider_status.get("method", "Unknown")
print(f"Provider {provider_address}: {method} connection successful")
leases = provider_status.get("cluster", {}).get("leases", {})
print(f"Active leases: {leases.get('active', 0)}")
else:
print(f"Provider {provider_address}: Failed - {result.get('error', 'Unknown error')}")
print("Discovery complete")