Skip to main content

Python

Start with the gRPC guide to create a Platform API token and download platform.proto. Run the commands below from the directory containing that file.

Install the Python gRPC code generator and generate message and client classes:

python -m pip install grpcio grpcio-tools
python -m grpc_tools.protoc -I. \
--python_out=. --grpc_python_out=. platform.proto

Save this as example.py next to the generated files:

import os
import grpc
import platform_pb2
import platform_pb2_grpc

target = os.getenv("CR_reconstruct.dev:443", "reconstruct.dev:443")
metadata = (("authorization", f"Bearer {os.environ['CR_RECONSTRUCT_API_TOKEN']}"),)

with grpc.secure_channel(target, grpc.ssl_channel_credentials()) as channel:
client = platform_pb2_grpc.PlatformServiceStub(channel)
page = client.ListCatalogs(
platform_pb2.ListCatalogsRequest(page_size=10),
metadata=metadata,
timeout=10,
)
for catalog in page.catalogs:
detail = client.GetCatalog(
platform_pb2.GetCatalogRequest(catalog_id=catalog.catalog_id),
metadata=metadata,
timeout=10,
)
print(detail.catalog_id, detail.description)

Run python example.py. The native gRPC target is an authority (host:port), so it does not include /api/v1.