技能 编程开发 Hex SDK 生产级最佳实践

Hex SDK 生产级最佳实践

v20260423
hex-sdk-patterns
本技能集提供了一套用于与Hex平台API集成的生产级开发模式。它涵盖了包括TypeScript和Python在内的多种语言的最佳实践,包括健壮的重试逻辑、类型安全客户端使用、流程编排以及Airflow集成,旨在帮助开发者建立标准化、可靠的Hex工作流编码标准。
获取技能
308 次下载
概览

Hex SDK Patterns

Overview

Production patterns for Hex API: typed client, pipeline orchestration, retry logic, and Python integration.

Instructions

Step 1: Run with Retry

async function runWithRetry(client: HexClient, projectId: string, params: Record<string, any>, maxRetries = 2) {
  for (let i = 0; i <= maxRetries; i++) {
    try {
      const { runId } = await client.runProject(projectId, params);
      const result = await pollUntilComplete(client, projectId, runId);
      return result;
    } catch (err: any) {
      if (i === maxRetries || !err.message.includes('429')) throw err;
      await new Promise(r => setTimeout(r, 30000)); // Wait 30s on rate limit
    }
  }
}

Step 2: Python Client (hextoolkit)

# pip install hextoolkit
from hextoolkit import HexAPI

hex_api = HexAPI(token=os.environ['HEX_API_TOKEN'])

# List projects
projects = hex_api.list_projects()

# Run project
run = hex_api.run_project('project-id', input_params={'date': '2025-01-01'})

# Poll for completion
status = hex_api.get_run_status('project-id', run['runId'])

Step 3: Airflow Integration

# Using the hex-inc/airflow-provider-hex package
from airflow_provider_hex.operators.hex import HexRunProjectOperator

run_task = HexRunProjectOperator(
    task_id='run_hex_project',
    project_id='your-project-id',
    input_params={'date': '{{ ds }}'},
    hex_conn_id='hex_default',
    wait_for_completion=True,
    timeout=600,
)

Resources

Next Steps

Apply patterns in hex-core-workflow-a.

信息
Category 编程开发
Name hex-sdk-patterns
版本 v20260423
大小 2.16KB
更新时间 2026-04-26
语言