> ## Documentation Index
> Fetch the complete documentation index at: https://ppio.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 列出 Template

你可以通过 CLI 或 SDK 以编程方式列出可用的 Sandbox Template。SDK 会返回每个 Template 的 ID、别名或名称、资源规格、可见性以及构建元数据。

## 示例

<CodeGroup>
  ```python Python theme={null}
  from ppio_sandbox import PPIO

  ppio = PPIO()

  res = ppio.template.list(
      template_type="template_build",  # or "snapshot_template"
      page=1,
      limit=20,
  )

  print(f"total: {res.total}, pages: {res.total_pages}")
  for t in res.items:
      print(t.template_id, t.aliases, t.cpu_count, t.memory_mb, t.public)
  ```

  ```javascript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

  const paginator = ppio.template.list({
    templateType: 'template_build', // or 'snapshot_template'
    page: 1,
    limit: 20,
  })

  const page = await paginator.nextPage()
  console.log(`total: ${page.total}, pages: ${page.totalPages}`)
  for (const t of page.templates) {
    console.log(t.templateId, t.aliases, t.cpuCount, t.memoryMB, t.public)
  }
  ```

  ```bash CLI theme={null}
  # 默认以 Pretty table 输出
  ppio template list

  # JSON 格式输出
  ppio template list --output json
  ```
</CodeGroup>

## 响应

响应为分页结构。顶层字段如下:

| 字段           | 类型              | 说明               |
| ------------ | --------------- | ---------------- |
| `templates`  | TemplateInfo\[] | 当前页的 Template 列表 |
| `total`      | number          | Template 总数      |
| `page`       | number          | 当前页码             |
| `limit`      | number          | 每页条数             |
| `totalPages` | number          | 总页数              |

`templates` 中的每一项包含:

| 字段(JS / Python)                     | 类型             | 说明                 |
| ----------------------------------- | -------------- | ------------------ |
| `templateId` / `template_id`        | string         | Template ID        |
| `aliases` / `names`                 | string\[]      | Template 别名 / 名称   |
| `cpuCount` / `cpu_count`            | number         | vCPU 数量            |
| `memoryMB` / `memory_mb`            | number         | 内存大小(MiB)          |
| `diskSizeMB` / `disk_size_mb`       | number         | 磁盘大小(MiB)          |
| `envdVersion` / `envd_version`      | string         | Envd 版本            |
| `public`                            | boolean        | Template 是否公开      |
| `buildId` / `build_id`              | string         | 最新构建 ID            |
| `buildCount` / `build_count`        | number         | 构建次数               |
| `createdAt` / `created_at`          | Date           | 创建时间               |
| `updatedAt` / `updated_at`          | Date           | 最后更新时间             |
| `lastSpawnedAt` / `last_spawned_at` | Date \| null   | 最近一次生成 Sandbox 的时间 |
| `createdBy` / `created_by`          | object \| null | 创建者(`id`、`email`)  |
