AgentbaseDocs
文档目录

Console SDK(Python)

Python 管理面 SDK(pip 包 agentbase-console-python-sdk,import namespace agentbase_console)覆盖 Console / 管理面 API:组织与项目治理、Key 签发、跨项目运维,与 Server 包(../server-sdk/python.md)可在同一环境共存。Node / Java / Go 面见同目录 nodejs.md / java.md / go.md。

制品与安装

制品未发布到 PyPI:从 agentbase-sdks release ZIP 解压后 pip 安装 Console wheel,完整命令见 ../examples/python.md「获取与安装」。

初始化与认证装载

Console 登录响应体不含 session secret(只在 a_session_console cookie),先经原始 HTTP 登录取 cookie,再挂到 Console SDK client:

import re

import requests
from agentbase_console.client import Client as ConsoleClient

resp = requests.post(
    'https://appbuild.oceanbase.com/v1/account/sessions/email',
    headers={'X-Appwrite-Project': 'console', 'Content-Type': 'application/json'},
    json={'email': CONSOLE_EMAIL, 'password': CONSOLE_PASSWORD},
)
secret = re.search(r'a_session_console=([^;]+)', resp.headers['set-cookie']).group(1)

console_client = (
    ConsoleClient()
    .set_endpoint('https://appbuild.oceanbase.com/v1')
    .set_project('console')
)
console_client.add_header('origin', 'https://appbuild.oceanbase.com')
console_client.add_header('x-forwarded-host', 'appbuild.oceanbase.com')
console_client.add_header('Cookie', f'a_session_console={secret}')

典型治理调用

服务面(agentbase_console.services)含 account、teams、projects、users、proxy、migrations 等;方法名与 Server 包同为 snake_case:

from agentbase_console.services.projects import Projects
from agentbase_console.services.teams import Teams

teams = Teams(console_client)
projects = Projects(console_client)

teams.create(team_id='my-team', name='My Team', roles=['owner'])
project = projects.create(project_id='unique()', name='My Project', team_id='my-team')
key = projects.create_key(
    project_id=project.id,
    name='server key',
    scopes=['users.read', 'users.write', 'teams.read', 'teams.write'],
    key_id='unique()',
)
print(key.secret)   # Server SDK 用的 API Key,只在创建响应出现一次

组织、成员、平台注册等 Console-only 操作不能用项目 API Key。

功能面导航

治理域到服务的全量映射见 nodejs.md「功能面导航」;各域功能页:组织、项目与 Key、配额、用量、站点与域名、平台运维。

错误与边界

各语言调用示例

以下按功能域给出各语言调用示例;每个卡片可切换语言(全页同步)。

建团队、项目与签发 Key

Python 方法名为 snake_case、Go 为 facade New* 构造器 + With* 可选项。该域无 REST 直调页签,REST 直调见下文「配额与限频」卡。

import { Client, Teams, Projects, ID, Scopes } from 'agentbase-console-sdk';

const client = new Client()
    .setEndpoint(process.env.APPBASE_ENDPOINT!)           // https://appbuild.oceanbase.com/v1
    .setProject(process.env.APPBASE_CONSOLE_PROJECT_ID!); // Console 项目,常为 console

const teams = new Teams(client);
const team = await teams.create({ teamId: ID.unique(), name: 'My Team' });

const projects = new Projects(client);
const project = await projects.create({
    projectId: ID.unique(),
    name: 'todo-app',
    teamId: team.$id,
    region: 'default'        // 不使用 Appwrite Cloud 的区域枚举
});

const key = await projects.createKey({
    projectId: project.$id,
    name: 'setup-script',
    scopes: [Scopes.UsersRead, Scopes.UsersWrite]   // scope 最小化
});
// key.secret 仅创建时返回一次

用量查询

三级聚合(最近 30 个 UTC 日)与旧口径是两套体系,方法名不可互猜(见 用量)。

// account / organizations / projects 为 Console SDK 对应 service 实例
await account.listUsageAggregates();
await organizations.listUsageAggregates({ organizationId: '<organizationId>' });
await projects.listUsageAggregates({ projectId: '<projectId>' });

配额与限频(REST 直调)

Python Console 面亦无 typed quota/ratelimit 证据,统一走 REST 入口:

# 查询当前配额与限频:
curl -sS "$APPBASE_ENDPOINT/projects/<projectId>/limits" \
  -H "X-Appwrite-Project: $APPBASE_CONSOLE_PROJECT_ID" \
  -H "X-Appwrite-Key: $APPBASE_CONSOLE_API_KEY"
# 设置:PATCH 同路径,body 为扁平的限频 + 配额字段;Quota 0 = 不限量,RateLimit 必须正整数
curl -sS -X PATCH "$APPBASE_ENDPOINT/projects/<projectId>/limits" \
  -H 'Content-Type: application/json' \
  -H "X-Appwrite-Project: $APPBASE_CONSOLE_PROJECT_ID" \
  -H "X-Appwrite-Key: $APPBASE_CONSOLE_API_KEY" \
  -d '{"databaseStorageLimit": 0}'
# 字段全集与字段名陷阱见 limits.mdx

示例指引

事实源