Python Client for Sui gRPC
Generate Python clients from official Sui v2 protobuf definitions and query Dwellir with TLS, metadata authentication, and a deadline.
Sui RPC endpoint: endpoint URLs, plans and pricing.
Generate the v2 clients, then call LedgerService.GetServiceInfo. The service reports the network, node version, checkpoint height, and retention bounds.
Install dependencies
mkdir sui-grpc-python
cd sui-grpc-python
python3 -m venv .venv
source .venv/bin/activate
pip install grpcio grpcio-tools googleapis-common-protos
git clone --depth 1 https://github.com/MystenLabs/sui-apis.git
mkdir -p protos
cp -R sui-apis/proto/. protos/Generate all Sui v2 client stubs
PROTO_INCLUDE=$(python -c 'import grpc_tools, pathlib; print(pathlib.Path(grpc_tools.__file__).parent / "_proto")')
python -m grpc_tools.protoc \
-I./protos -I"$PROTO_INCLUDE" \
--python_out=. --grpc_python_out=. \
./protos/sui/rpc/v2/*.protoKeep the complete directory tree. Generated modules import other Sui v2 messages and Google protobuf types.
Query service information
Save this as client.py:
import os
import grpc
from sui.rpc.v2 import ledger_service_pb2, ledger_service_pb2_grpc
endpoint = 'api-sui-mainnet-full.n.dwellir.com:443'
metadata = [('x-api-key', os.environ['DWELLIR_API_KEY'])]
with grpc.secure_channel(endpoint, grpc.ssl_channel_credentials()) as channel:
client = ledger_service_pb2_grpc.LedgerServiceStub(channel)
response = client.GetServiceInfo(
ledger_service_pb2.GetServiceInfoRequest(),
metadata=metadata,
timeout=10,
)
print(response.chain, response.server, response.checkpoint_height)Set DWELLIR_API_KEY in your environment, then run:
python client.pyPython protobuf fields use snake_case. Responses retain their envelopes: object reads return response.object, and epoch reads return response.epoch.
Use a field mask
from google.protobuf import field_mask_pb2
request = ledger_service_pb2.GetObjectRequest(
object_id='0x5',
read_mask=field_mask_pb2.FieldMask(paths=['object_id', 'version']),
)Call GetObject with this request inside an open channel. The mask applies to response.object, rather than the outer response message.
Execution and subscriptions
The execution stub is transaction_execution_service_pb2_grpc.TransactionExecutionServiceStub.
Serialized bytes belong in Transaction.bcs.value. A serialized signature belongs in UserSignature.bcs.value.
See ExecuteTransaction and SimulateTransaction for their different mask roots.
Subscriptions require cancellation, bounded processing, and persisted progress. See SubscribeCheckpoints before building a recovery loop.
Check the deployed schema with grpcurl when regenerating clients.