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

# workspace の管理

> このセクションでは、Python SDK を使用して workspace を管理する方法を学びます。workspace を使うと、複数のアプリケーションをチームメンバーと整理・共同管理できます。

[Client]: client

workspace は、アプリケーションを整理してチームメンバーと共同作業するための仕組みです。Client クラスを使って workspace の作成、取得、一覧表示、削除を行えます。

## workspace の作成

`client.create_workspace` は `Workspace` オブジェクトを返します。

```python theme={null}
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` オブジェクトを返します。

```python theme={null}
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` オブジェクトのリストを返します。

```python theme={null}
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` オブジェクトを返します。

```python theme={null}
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` オブジェクトを返します。

```python theme={null}
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` オブジェクトには以下の情報が含まれます。

| プロパティ          | 型                   | 説明                              |
| -------------- | ------------------- | ------------------------------- |
| `id`           | `str`               | workspace の一意な識別子               |
| `name`         | `str`               | workspace 名                     |
| `owner`        | `Member`            | workspace のオーナー情報               |
| `members`      | `list[Member]`      | workspace メンバーのリスト              |
| `applications` | `list[Application]` | workspace に紐づくアプリケーション          |
| `createdAt`    | `str`               | workspace の作成タイムスタンプ (ISO 8601) |

## Member のデータ構造

workspace 内の各メンバーは以下の構造を持ちます。

| プロパティ   | 型     | 説明                          |
| ------- | ----- | --------------------------- |
| `id`    | `str` | メンバーの一意な識別子                 |
| `name`  | `str` | メンバーの表示名                    |
| `group` | `str` | workspace 内でのメンバーの役割またはグループ |
