Read Resource Inventories

Query catalogs, workflows, compute resources, and knowledge bases from a workspace handle to obtain catalog IDs, workflow IDs, compute resource IDs, and knowledge base IDs for downstream tasks.

Task flow

Workspace handle
    ├── List catalogs ───────────▶ Catalog IDs and names
    ├── List workflows ──────────▶ Workflow IDs, names, and statuses
    ├── List compute resources ──▶ Compute resource IDs and names
    └── List knowledge bases ────▶ Knowledge base IDs, names, and next-page token

Prerequisites

  1. Complete the endpoint, personal access token, and workspace setup in Use the SDK.

  2. Ensure the current identity has list permissions for the target resource types in the workspace.

Read each resource inventory

Each resource service paginates independently. The following example reads the first page of catalogs, workflows, compute resources, and knowledge bases in the current workspace and prints their IDs and names.

import os

import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"],
    os.environ["PRODUCT_API_KEY"],
)
workspace = client.workspace(os.environ["WORKSPACE_ID"])

catalogs = workspace.catalog().list()
for item in catalogs.list:
    print("Catalog:", item.id, item.name)

workflows = workspace.workflows().list()
for item in workflows.workflows:
    print("Workflow:", item.id, item.name, item.status)

for item in workspace.compute().list():
    print("Compute:", item.id, item.name)

knowledge = workspace.knowledge().list()
for item in knowledge.items:
    print("Knowledge base:", item.id, item.name)
print("Knowledge next-page token:", knowledge.next_page_token)
package main

import (
	"context"
	"fmt"
	"os"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	ctx := context.Background()
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		panic(err)
	}
	workspace, err := client.Workspace(os.Getenv("WORKSPACE_ID"))
	if err != nil {
		panic(err)
	}

	catalogs, err := workspace.Catalog().List(ctx)
	if err != nil {
		panic(err)
	}
	for _, item := range catalogs.GetList() {
		fmt.Println("Catalog:", item.GetId(), item.GetName())
	}

	workflows, err := workspace.Workflows().List(ctx)
	if err != nil {
		panic(err)
	}
	for _, item := range workflows.GetWorkflows() {
		fmt.Println("Workflow:", item.GetId(), item.GetName(), item.GetStatus())
	}

	compute, err := workspace.Compute().List(ctx)
	if err != nil {
		panic(err)
	}
	for _, item := range compute {
		fmt.Println("Compute:", item.GetId(), item.GetName())
	}

	knowledge, err := workspace.Knowledge().List(ctx)
	if err != nil {
		panic(err)
	}
	for _, item := range knowledge.GetItems() {
		fmt.Println("Knowledge base:", item.GetId(), item.GetName())
	}
	fmt.Println("Knowledge next-page token:", knowledge.GetNextPageToken())
}

Each call returns a single page; when the total exceeds the current page size or next_page_token is non-empty, pass pagination options to the corresponding service to retrieve subsequent pages.

Next steps

Last updated on