跳转到主要内容
workspace 是一种组织应用并与团队成员协作的方式。你可以使用 Client 类来创建、获取、列出和删除 workspace。

创建 workspace

client.create_workspace 返回一个 Workspace 对象。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    workspace = await client.create_workspace(name='My Workspace')
    
    print(workspace.id)              # Workspace identifier
    print(workspace.name)             # 'My Workspace'
    print(workspace.owner)            # Owner member information
    print(workspace.members)          # List of workspace members
    print(workspace.applications)     # List of applications in the workspace
    print(workspace.createdAt)        # Workspace creation timestamp

获取 workspace

client.get_workspace 返回一个 Workspace 对象。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    workspace = await client.get_workspace(workspace_id='WORKSPACE_ID')
    
    print(workspace.id)          # Workspace identifier
    print(workspace.name)         # Workspace name
    print(workspace.owner)        # Owner member information
    print(workspace.members)      # List of workspace members
    print(workspace.applications) # List of applications in the workspace

列出所有 workspace

client.all_workspaces 返回一个由 Workspace 对象组成的列表。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    workspaces = await client.all_workspaces()
    
    for workspace in workspaces:
        print(f"Workspace: {workspace.name} (ID: {workspace.id})")
        print(f"  Owner: {workspace.owner.name}")
        print(f"  Members: {len(workspace.members)}")
        print(f"  Applications: {len(workspace.applications)}")

删除 workspace

client.delete_workspace 返回一个 Response 对象。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.delete_workspace(workspace_id='WORKSPACE_ID')
    print(f"Workspace deleted successfully: {response.status}")

退出 workspace

如果你是某个 workspace 的成员但不是所有者,可以使用 client.leave_workspace 退出该 workspace,它会返回一个 Response 对象。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    response = await client.leave_workspace(workspace_id='WORKSPACE_ID')
    print(f"Left workspace successfully: {response.status}")

workspace 数据结构

Workspace 对象包含以下信息:
属性类型描述
idstrworkspace 唯一标识符
namestrworkspace 名称
ownerMemberworkspace 所有者信息
memberslist[Member]workspace 成员列表
applicationslist[Application]与该 workspace 关联的应用
createdAtstrworkspace 创建时间戳(ISO 8601)

成员数据结构

workspace 中的每个成员具有以下结构:
属性类型描述
idstr成员唯一标识符
namestr成员显示名称
groupstr成员在 workspace 中的角色或分组