Skip to content

Plugins

API clients for interacting with QLAM services.

Tasks Client

Tasks Client - Clean Python API for task operations.

This module provides a typed, presentation-free API for task management. It uses the executor abstraction to perform HTTP operations and returns strongly-typed Pydantic models.

Usage
from qlam_core.plugins.tasks.api.client import TasksClient
from qlam_core.common.context import AppContext

ctx = AppContext()

# Direct usage
client = TasksClient(ctx)
tasks = client.list()

# Context manager usage
with TasksClient(ctx) as client:
    tasks = client.list()

TasksClient

TasksClient(ctx: AppContext)

Bases: BaseRestApi, ListMixin[Task], ReadMixin[Task], WriteMixin[TaskCreationRequest, Task]


              flowchart TD
              qlam_core.plugins.tasks.api.client.TasksClient[TasksClient]
              qlam_core.sdk.base_api.BaseRestApi[BaseRestApi]
              qlam_core.plugins.common.mixins.ListMixin[ListMixin]
              qlam_core.plugins.common.mixins.ReadMixin[ReadMixin]
              qlam_core.plugins.common.mixins.WriteMixin[WriteMixin]

                              qlam_core.sdk.base_api.BaseRestApi --> qlam_core.plugins.tasks.api.client.TasksClient
                
                qlam_core.plugins.common.mixins.ListMixin --> qlam_core.plugins.tasks.api.client.TasksClient
                
                qlam_core.plugins.common.mixins.ReadMixin --> qlam_core.plugins.tasks.api.client.TasksClient
                
                qlam_core.plugins.common.mixins.WriteMixin --> qlam_core.plugins.tasks.api.client.TasksClient
                


              click qlam_core.plugins.tasks.api.client.TasksClient href "" "qlam_core.plugins.tasks.api.client.TasksClient"
              click qlam_core.sdk.base_api.BaseRestApi href "" "qlam_core.sdk.base_api.BaseRestApi"
              click qlam_core.plugins.common.mixins.ListMixin href "" "qlam_core.plugins.common.mixins.ListMixin"
              click qlam_core.plugins.common.mixins.ReadMixin href "" "qlam_core.plugins.common.mixins.ReadMixin"
              click qlam_core.plugins.common.mixins.WriteMixin href "" "qlam_core.plugins.common.mixins.WriteMixin"
            

Client for task operations.

This API provides explicit methods for task management that return Pydantic v2 models. It's presentation-free and can be used by any frontend (CLI, Web, GUI) or directly by Python consumers.

All methods automatically resolve QPU mode from configuration when not explicitly provided, using the @auto_resolve_qpu_mode decorator.

The client uses composition of mixins to provide standard CRUD operations
  • ListMixin: Provides list, list_page, iter_pages, list_all
  • ReadMixin: Provides get
  • WriteMixin: Provides create

Resource-specific operations (like cancel) are implemented directly in this class.

Example
# Create client
client = TasksClient(ctx)

# List operations (from ListMixin)
page = client.list_page(page=0, size=50)
all_tasks = client.list_all(max_items=1000)

# Read operations (from ReadMixin)
task = client.get(id="abc-123")

# Write operations (from WriteMixin)
request = TaskCreationRequest(...)
new_task = client.create(body=request)

# Resource-specific operations
cancelled = client.cancel(id="abc-123")

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/tasks/api/client.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(self, ctx: AppContext):
    """Initialize the tasks API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="tasks")

    # Configure mixins with tasks-specific details
    self._configure_list_mixin(
        spec=TASKS_SPEC,
        list_model=Task,
        list_command="list",
    )

    self._configure_read_mixin(
        spec=TASKS_SPEC,
        get_model=Task,
        get_command="gettask",
        id_param="id",
    )

    self._configure_write_mixin(
        spec=TASKS_SPEC,
        create_request_model=TaskCreationRequest,
        create_response_model=Task,
        create_command="create",
    )

cancel

cancel(qpu_mode: str | None = None, id: str | None = None) -> None

Request cancellation of a running task.

This method is a thin wrapper around the /cancel endpoint:

  • On success (HTTP 202), it returns None, indicating that the cancellation request was accepted and is being processed.
  • On failure (HTTP status >= 400 or network error), it propagates the underlying exception (typically :class:qlam_core.cli.errors.APIError).
Source code in qlam_core/plugins/tasks/api/client.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@auto_resolve_qpu_mode
def cancel(
    self,
    qpu_mode: str | None = None,
    id: str | None = None,  # noqa: A002
) -> None:
    """Request cancellation of a running task.

    This method is a thin wrapper around the ``/cancel`` endpoint:

    - On success (HTTP 202), it returns ``None``, indicating that the
      cancellation request was accepted and is being processed.
    - On failure (HTTP status >= 400 or network error), it propagates
      the underlying exception (typically :class:`qlam_core.cli.errors.APIError`).
    """
    self._exec.execute(TASKS_SPEC, "cancel", qpu_mode=qpu_mode, id=id)

Results Client

Results Client - API for retrieving task results.

Provides access to sanitized results via the Results Transformer by default, and unsanitized (raw) results via the Result Manager when requested.

ResultsClient

ResultsClient(ctx: AppContext)

Bases: BaseRestApi


              flowchart TD
              qlam_core.plugins.results.api.client.ResultsClient[ResultsClient]
              qlam_core.sdk.base_api.BaseRestApi[BaseRestApi]

                              qlam_core.sdk.base_api.BaseRestApi --> qlam_core.plugins.results.api.client.ResultsClient
                


              click qlam_core.plugins.results.api.client.ResultsClient href "" "qlam_core.plugins.results.api.client.ResultsClient"
              click qlam_core.sdk.base_api.BaseRestApi href "" "qlam_core.sdk.base_api.BaseRestApi"
            

Client for task results retrieval.

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/results/api/client.py
26
27
28
29
30
31
def __init__(self, ctx: AppContext):
    """Initialize the results API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="results")

download_to_path

download_to_path(output_path: str | PathLike[str], qpu_mode: str | None = None, id: str | None = None, *, raw_source: bool = False, sort: str | None = None) -> int

Stream the full task result response directly to output_path.

Source code in qlam_core/plugins/results/api/client.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def download_to_path(
    self,
    output_path: str | PathLike[str],
    qpu_mode: str | None = None,
    id: str | None = None,  # noqa: A002
    *,
    raw_source: bool = False,
    sort: str | None = None,
) -> int:
    """Stream the full task result response directly to ``output_path``."""
    path = Path(output_path)
    spec, kwargs = self._download_kwargs(
        id=id,
        raw_source=raw_source,
        qpu_mode=qpu_mode,
        sort=sort,
    )
    response = self._exec.stream_to_path(
        spec,
        "gettaskresult",
        path,
        expected_content_type=OCTET_STREAM_ACCEPT,
        **kwargs,
    )
    bytes_written = response.get("bytes_written", 0)
    return int(bytes_written)

get

get(qpu_mode: str | None = None, id: str | None = None, *, raw_source: bool = False, page: int = 0, size: int | None = None, sort: str | None = None, shots_page: int | None = None, shots_size: int | None = None) -> JsonDict

Get task results.

  • Default (sanitized): Results Transformer endpoint (requires qpu_mode).
  • Raw (unsanitized): Result Manager endpoint (--raw flag).
  • If sort is omitted, backend defaults are preserved.
Source code in qlam_core/plugins/results/api/client.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@auto_resolve_qpu_mode
def get(
    self,
    qpu_mode: str | None = None,
    id: str | None = None,  # noqa: A002
    *,
    raw_source: bool = False,
    page: int = 0,
    size: int | None = None,
    sort: str | None = None,
    shots_page: int | None = None,
    shots_size: int | None = None,
) -> JsonDict:
    """Get task results.

    - Default (sanitized): Results Transformer endpoint (requires qpu_mode).
    - Raw (unsanitized): Result Manager endpoint (--raw flag).
    - If ``sort`` is omitted, backend defaults are preserved.
    """
    spec = RESULT_MANAGER_SPEC if raw_source else RESULT_TRANSFORMER_SPEC

    kwargs: JsonDict = {
        "task_id": id,
        "page": page,
        "size": size,
        "shots_page": shots_page,
        "shots_size": shots_size,
    }
    if sort is not None:
        kwargs["sort"] = sort

    # Only include qpu_mode for the transformer endpoint
    if not raw_source:
        kwargs["qpu_mode"] = qpu_mode

    return self._exec.execute(spec, "gettaskresult", **kwargs)

Compilations Client

Compilations API - Clean Python API for compilation operations.

This module provides a typed, presentation-free API for compilation management. It uses the executor abstraction to perform HTTP operations and returns strongly-typed Pydantic models.

CompilationsClient

CompilationsClient(ctx: AppContext)

Bases: BaseRestApi, ListMixin[PublicCompilation], ReadMixin[PrivateCompilation], WriteMixin[V2QpuModeCompilationsPostRequest, PrivateCompilation]


              flowchart TD
              qlam_core.plugins.compilations.api.client.CompilationsClient[CompilationsClient]
              qlam_core.sdk.base_api.BaseRestApi[BaseRestApi]
              qlam_core.plugins.common.mixins.ListMixin[ListMixin]
              qlam_core.plugins.common.mixins.ReadMixin[ReadMixin]
              qlam_core.plugins.common.mixins.WriteMixin[WriteMixin]

                              qlam_core.sdk.base_api.BaseRestApi --> qlam_core.plugins.compilations.api.client.CompilationsClient
                
                qlam_core.plugins.common.mixins.ListMixin --> qlam_core.plugins.compilations.api.client.CompilationsClient
                
                qlam_core.plugins.common.mixins.ReadMixin --> qlam_core.plugins.compilations.api.client.CompilationsClient
                
                qlam_core.plugins.common.mixins.WriteMixin --> qlam_core.plugins.compilations.api.client.CompilationsClient
                


              click qlam_core.plugins.compilations.api.client.CompilationsClient href "" "qlam_core.plugins.compilations.api.client.CompilationsClient"
              click qlam_core.sdk.base_api.BaseRestApi href "" "qlam_core.sdk.base_api.BaseRestApi"
              click qlam_core.plugins.common.mixins.ListMixin href "" "qlam_core.plugins.common.mixins.ListMixin"
              click qlam_core.plugins.common.mixins.ReadMixin href "" "qlam_core.plugins.common.mixins.ReadMixin"
              click qlam_core.plugins.common.mixins.WriteMixin href "" "qlam_core.plugins.common.mixins.WriteMixin"
            

Typed API for compilation operations.

This API provides explicit methods for compilation management that return Pydantic v2 models. It's presentation-free and can be used by any frontend (CLI, Web, GUI) or directly by Python consumers.

All methods automatically resolve QPU mode from configuration when not explicitly provided, using the @auto_resolve_qpu_mode decorator.

The client uses composition of mixins to provide standard CRUD operations
  • ListMixin: Provides list, list_page, iter_pages, list_all
  • ReadMixin: Provides get
  • WriteMixin: Provides create
Example
# Create client
client = CompilationsClient(ctx)

# List operations
page = client.list_page(page=0, size=50)
all_compilations = client.list_all(max_items=1000)

# Read operations
compilation = client.get(id="abc-123")

# Write operations
request = V2QpuModeCompilationsPostRequest(...)
new_compilation = client.create(body=request)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/compilations/api/client.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __init__(self, ctx: AppContext):
    """Initialize the compilations API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="compilations")

    # Configure mixins with compilations-specific details
    self._configure_list_mixin(
        spec=COMPILATIONS_SPEC,
        list_model=PublicCompilation,
        list_command="list",
    )

    self._configure_read_mixin(
        spec=COMPILATIONS_SPEC,
        get_model=PrivateCompilation,
        get_command="getcompilation",
        id_param="id",
    )

    self._configure_write_mixin(
        spec=COMPILATIONS_SPEC,
        create_request_model=V2QpuModeCompilationsPostRequest,
        create_response_model=PrivateCompilation,
        create_command="create",
    )

Definitions Client

Definitions API - Clean Python API for task definition operations.

This module provides a typed, presentation-free API for task definition management. It uses the executor abstraction to perform HTTP operations and returns strongly-typed Pydantic models.

DefinitionsClient

DefinitionsClient(ctx: AppContext)

Bases: BaseRestApi, ListMixin[TaskDefinitionResponse], ReadMixin[TaskDefinitionResponse], WriteMixin[TaskDefinitionRequest, TaskDefinitionResponse]


              flowchart TD
              qlam_core.plugins.definitions.api.client.DefinitionsClient[DefinitionsClient]
              qlam_core.sdk.base_api.BaseRestApi[BaseRestApi]
              qlam_core.plugins.common.mixins.ListMixin[ListMixin]
              qlam_core.plugins.common.mixins.ReadMixin[ReadMixin]
              qlam_core.plugins.common.mixins.WriteMixin[WriteMixin]

                              qlam_core.sdk.base_api.BaseRestApi --> qlam_core.plugins.definitions.api.client.DefinitionsClient
                
                qlam_core.plugins.common.mixins.ListMixin --> qlam_core.plugins.definitions.api.client.DefinitionsClient
                
                qlam_core.plugins.common.mixins.ReadMixin --> qlam_core.plugins.definitions.api.client.DefinitionsClient
                
                qlam_core.plugins.common.mixins.WriteMixin --> qlam_core.plugins.definitions.api.client.DefinitionsClient
                


              click qlam_core.plugins.definitions.api.client.DefinitionsClient href "" "qlam_core.plugins.definitions.api.client.DefinitionsClient"
              click qlam_core.sdk.base_api.BaseRestApi href "" "qlam_core.sdk.base_api.BaseRestApi"
              click qlam_core.plugins.common.mixins.ListMixin href "" "qlam_core.plugins.common.mixins.ListMixin"
              click qlam_core.plugins.common.mixins.ReadMixin href "" "qlam_core.plugins.common.mixins.ReadMixin"
              click qlam_core.plugins.common.mixins.WriteMixin href "" "qlam_core.plugins.common.mixins.WriteMixin"
            

Typed API for task definition operations.

This API provides explicit methods for task definition management that return Pydantic v2 models. It's presentation-free and can be used by any frontend (CLI, Web, GUI) or directly by Python consumers.

All methods automatically resolve QPU mode from configuration when not explicitly provided, using the @auto_resolve_qpu_mode decorator.

The client uses composition of mixins to provide standard CRUD operations
  • ListMixin: Provides list, list_page, iter_pages, list_all
  • ReadMixin: Provides get
  • WriteMixin: Provides create
Example
# Create client
client = DefinitionsClient(ctx)

# List operations
page = client.list_page(page=0, size=50)
all_definitions = client.list_all(max_items=1000)

# Read operations
definition = client.get(id="abc-123")

# Write operations
definition = TaskDefinitionRequest(...)
new_definition = client.create(body=definition)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/definitions/api/client.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __init__(self, ctx: AppContext):
    """Initialize the definitions API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="definitions")

    # Configure mixins with definitions-specific details
    self._configure_list_mixin(
        spec=DEFINITIONS_SPEC,
        list_model=TaskDefinitionResponse,
        list_command="list",
    )

    self._configure_read_mixin(
        spec=DEFINITIONS_SPEC,
        get_model=TaskDefinitionResponse,
        get_command="getdefinition",
        id_param="id",
    )

    self._configure_write_mixin(
        spec=DEFINITIONS_SPEC,
        create_request_model=TaskDefinitionRequest,
        create_response_model=TaskDefinitionResponse,
        create_command="create",
    )

Tenants Client

Tenants Client - Clean Python API for tenant management.

This module provides a typed, presentation-free API for tenant lifecycle and tenant audience management. It talks to the non-QPU-scoped user-tenant service and returns strongly-typed Pydantic models.

Usage
from qlam_core.common.context import AppContext
from qlam_core.plugins.tenants import TenantsClient

ctx = AppContext()

with TenantsClient(ctx) as client:
    first_page = client.list_page(size=25)
    tenant = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
    access = client.get_audiences(id=tenant.id)

TenantsClient

TenantsClient(ctx: AppContext)

Bases: BaseRestApiWithoutQpuMode


              flowchart TD
              qlam_core.plugins.tenants.api.client.TenantsClient[TenantsClient]
              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode[BaseRestApiWithoutQpuMode]

                              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode --> qlam_core.plugins.tenants.api.client.TenantsClient
                


              click qlam_core.plugins.tenants.api.client.TenantsClient href "" "qlam_core.plugins.tenants.api.client.TenantsClient"
              click qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode href "" "qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode"
            

Typed API for tenant and tenant-audience operations.

This client provides explicit methods for listing, creating, and retrieving tenants, plus reading and replacing tenant audience access configuration.

Unlike QPU-scoped clients such as TasksClient, this client targets the user-tenant service and therefore does not accept or resolve qpu_mode. The tenants endpoints are public-only and reject Visibility.PRIVATE.

Example
client = TenantsClient(ctx)

page = client.list_page(page=0, size=50)
tenant = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
audiences = client.get_audiences(id=tenant.id)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/tenants/api/client.py
59
60
61
62
63
64
def __init__(self, ctx: AppContext):
    """Initialize the tenants API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="user_tenant")

create

create(body: CreateTenantRequest | dict[str, object]) -> TenantResponse

Create a tenant.

:param body: A validated request model or a JSON-like dictionary. :returns: The created tenant as a TenantResponse.

Source code in qlam_core/plugins/tenants/api/client.py
171
172
173
174
175
176
177
178
179
180
181
def create(self, body: CreateTenantRequest | dict[str, object]) -> TenantResponse:
    """Create a tenant.

    :param body: A validated request model or a JSON-like dictionary.
    :returns: The created tenant as a ``TenantResponse``.
    """
    response = self._execute(
        "create_tenant",
        data=body.model_dump(mode="json", exclude_none=True) if isinstance(body, CreateTenantRequest) else body,
    )
    return TenantResponse.model_validate(response)

get

get(id: UUID | str) -> TenantResponse

Fetch one tenant by UUID.

:param id: Tenant UUID as a UUID or UUID string. :returns: The validated tenant response model.

Source code in qlam_core/plugins/tenants/api/client.py
159
160
161
162
163
164
165
166
167
168
169
def get(self, id: UUID | str) -> TenantResponse:  # noqa: A002
    """Fetch one tenant by UUID.

    :param id: Tenant UUID as a ``UUID`` or UUID string.
    :returns: The validated tenant response model.
    """
    response = self._execute(
        "get_tenant",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return TenantResponse.model_validate(response)

get_audiences

get_audiences(id: UUID | str) -> TenantQpuAccess

Fetch configured tenant audience access.

:param id: Tenant UUID as a UUID or UUID string. :returns: The tenant's configured TenantQpuAccess payload.

Source code in qlam_core/plugins/tenants/api/client.py
183
184
185
186
187
188
189
190
191
192
193
def get_audiences(self, id: UUID | str) -> TenantQpuAccess:  # noqa: A002
    """Fetch configured tenant audience access.

    :param id: Tenant UUID as a ``UUID`` or UUID string.
    :returns: The tenant's configured ``TenantQpuAccess`` payload.
    """
    response = self._execute(
        "get_tenant_audiences",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return TenantQpuAccess.model_validate(response)

iter_pages

iter_pages(start_page: int = 0, size: int | None = None, max_pages: int | None = None) -> Iterator[Page[TenantResponse]]

Yield tenant pages lazily.

Use this when you want to stream through paginated results without collecting every tenant in memory up front.

:param start_page: Zero-based page index to start from. :param size: Optional page size. :param max_pages: Optional maximum number of pages to yield. :returns: An iterator of typed tenant pages.

Source code in qlam_core/plugins/tenants/api/client.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def iter_pages(
    self,
    start_page: int = 0,
    size: int | None = None,
    max_pages: int | None = None,
) -> Iterator[Page[TenantResponse]]:
    """Yield tenant pages lazily.

    Use this when you want to stream through paginated results without
    collecting every tenant in memory up front.

    :param start_page: Zero-based page index to start from.
    :param size: Optional page size.
    :param max_pages: Optional maximum number of pages to yield.
    :returns: An iterator of typed tenant pages.
    """
    current_page = start_page
    fetched_pages = 0

    while True:
        if max_pages is not None and fetched_pages >= max_pages:
            break

        page_result = self.list_page(page=current_page, size=size)
        if not page_result.items:
            break

        yield page_result
        fetched_pages += 1

        if not page_result.has_next:
            break

        current_page += 1

list

list(page: int = 0, size: int | None = None) -> list[TenantResponse]

Return tenants from a single page.

This is a convenience wrapper around :meth:list_page that returns only the page items.

Source code in qlam_core/plugins/tenants/api/client.py
92
93
94
95
96
97
98
def list(self, page: int = 0, size: int | None = None) -> list[TenantResponse]:
    """Return tenants from a single page.

    This is a convenience wrapper around :meth:`list_page` that returns
    only the page items.
    """
    return self.list_page(page=page, size=size).items

list_all

list_all(size: int | None = None, max_items: int | None = None) -> list[TenantResponse]

Return tenants across all pages.

This eagerly collects items from :meth:iter_pages into a single list.

:param size: Optional page size. :param max_items: Optional cap on the total number of items returned. :returns: A list of TenantResponse objects.

Source code in qlam_core/plugins/tenants/api/client.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def list_all(
    self,
    size: int | None = None,
    max_items: int | None = None,
) -> list[TenantResponse]:
    """Return tenants across all pages.

    This eagerly collects items from :meth:`iter_pages` into a single list.

    :param size: Optional page size.
    :param max_items: Optional cap on the total number of items returned.
    :returns: A list of ``TenantResponse`` objects.
    """
    if max_items == 0:
        return []

    items: list[TenantResponse] = []
    for page_result in self.iter_pages(size=size):
        items.extend(page_result.items)
        if max_items is not None and len(items) >= max_items:
            return items[:max_items]

    return items

list_page

list_page(page: int = 0, size: int | None = None) -> Page[TenantResponse]

Return one page of tenants.

:param page: Zero-based page index. :param size: Optional page size. If omitted, the server default is used. :returns: A typed page of TenantResponse items.

Source code in qlam_core/plugins/tenants/api/client.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def list_page(self, page: int = 0, size: int | None = None) -> Page[TenantResponse]:
    """Return one page of tenants.

    :param page: Zero-based page index.
    :param size: Optional page size. If omitted, the server default is used.
    :returns: A typed page of ``TenantResponse`` items.
    """
    response = self._execute(
        "list_tenants",
        page=page,
        size=size,
    )
    parsed = PageTenantResponse.model_validate(response)
    return Page(
        items=list(parsed.elements),
        page_number=parsed.page,
        page_size=parsed.size,
        total_items=parsed.total,
    )

set_audiences

set_audiences(id: UUID | str, body: TenantQpuAccess | dict[str, object]) -> TenantQpuAccess

Replace configured tenant audience access.

The backend validates the canonical audience URIs in the request and will reject duplicate or unknown entries.

:param id: Tenant UUID as a UUID or UUID string. :param body: A validated TenantQpuAccess model or JSON-like dict. :returns: The updated tenant audience configuration.

Source code in qlam_core/plugins/tenants/api/client.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def set_audiences(
    self,
    id: UUID | str,  # noqa: A002
    body: TenantQpuAccess | dict[str, object],
) -> TenantQpuAccess:
    """Replace configured tenant audience access.

    The backend validates the canonical audience URIs in the request and
    will reject duplicate or unknown entries.

    :param id: Tenant UUID as a ``UUID`` or UUID string.
    :param body: A validated ``TenantQpuAccess`` model or JSON-like dict.
    :returns: The updated tenant audience configuration.
    """
    response = self._execute(
        "set_tenant_audiences",
        uuid=str(id) if isinstance(id, UUID) else id,
        data=body.model_dump(mode="json", exclude_none=True) if isinstance(body, TenantQpuAccess) else body,
    )
    return TenantQpuAccess.model_validate(response)

Users Client

Users Client - Clean Python API for user management.

This module provides a typed, presentation-free API for user lifecycle, user detail, role, and group-assignment management. It talks to the non-QPU-scoped user-tenant service and returns strongly-typed Pydantic models.

Usage
from qlam_core.common.context import AppContext
from qlam_core.plugins.users import UsersClient

ctx = AppContext()

with UsersClient(ctx) as client:
    page = client.list_page(size=25)
    user = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
    roles = client.get_roles(id=user.id)
    groups = client.get_groups(id=user.id)

UsersClient

UsersClient(ctx: AppContext)

Bases: BaseRestApiWithoutQpuMode


              flowchart TD
              qlam_core.plugins.users.api.client.UsersClient[UsersClient]
              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode[BaseRestApiWithoutQpuMode]

                              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode --> qlam_core.plugins.users.api.client.UsersClient
                


              click qlam_core.plugins.users.api.client.UsersClient href "" "qlam_core.plugins.users.api.client.UsersClient"
              click qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode href "" "qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode"
            

Typed API for user and user-role operations.

This client provides explicit methods for listing, creating, updating, and retrieving users, along with helpers for role-assignment and password-change endpoints.

Unlike QPU-scoped clients such as TasksClient, this client targets the user-tenant service and therefore does not accept or resolve qpu_mode. Role updates use the service's bare JSON list request body rather than a wrapper object. The users endpoints are public-only and reject Visibility.PRIVATE.

Example
client = UsersClient(ctx)

page = client.list_page(page=0, size=50)
user = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
roles = client.get_roles(id=user.id)
groups = client.get_groups(id=user.id)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/users/api/client.py
112
113
114
115
116
117
def __init__(self, ctx: AppContext):
    """Initialize the users API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="user_tenant")

change_password

change_password(id: UUID | str) -> None

Trigger the backend change-password flow for a user.

The underlying endpoint returns HTTP 204 with no response body on success, so this method returns None.

:param id: User UUID as a UUID or UUID string.

Source code in qlam_core/plugins/users/api/client.py
423
424
425
426
427
428
429
430
431
432
433
434
def change_password(self, id: UUID | str) -> None:  # noqa: A002
    """Trigger the backend change-password flow for a user.

    The underlying endpoint returns HTTP 204 with no response body on
    success, so this method returns ``None``.

    :param id: User UUID as a ``UUID`` or UUID string.
    """
    self._execute(
        "change_password",
        uuid=str(id) if isinstance(id, UUID) else id,
    )

create

create(body: CreateUserRequest | dict[str, object]) -> UserResponse

Create a user.

:param body: A validated request model or a JSON-like dictionary. :returns: The created user as a UserResponse.

Source code in qlam_core/plugins/users/api/client.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def create(self, body: CreateUserRequest | dict[str, object]) -> UserResponse:
    """Create a user.

    :param body: A validated request model or a JSON-like dictionary.
    :returns: The created user as a ``UserResponse``.
    """
    request = (
        CreateUserRequest.model_validate(body) if isinstance(body, dict) else body
    )
    response = self._execute(
        "create_user",
        data=request.model_dump(
            mode="json",
            exclude_none=True,
            include=set(CreateUserRequest.model_fields),
        ),
    )
    return UserResponse.model_validate(response)

get

get(id: UUID | str) -> UserResponse

Fetch one user by UUID.

:param id: User UUID as a UUID or UUID string. :returns: The validated user response model.

Source code in qlam_core/plugins/users/api/client.py
309
310
311
312
313
314
315
316
317
318
319
def get(self, id: UUID | str) -> UserResponse:  # noqa: A002
    """Fetch one user by UUID.

    :param id: User UUID as a ``UUID`` or UUID string.
    :returns: The validated user response model.
    """
    response = self._execute(
        "get_user",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return UserResponse.model_validate(response)

get_details

get_details(id: UUID | str) -> UserDetailsResponse

Fetch the detailed user profile.

:param id: User UUID as a UUID or UUID string. :returns: The validated UserDetailsResponse model.

Source code in qlam_core/plugins/users/api/client.py
362
363
364
365
366
367
368
369
370
371
372
def get_details(self, id: UUID | str) -> UserDetailsResponse:  # noqa: A002
    """Fetch the detailed user profile.

    :param id: User UUID as a ``UUID`` or UUID string.
    :returns: The validated ``UserDetailsResponse`` model.
    """
    response = self._execute(
        "get_user_details",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return UserDetailsResponse.model_validate(response)

get_groups

get_groups(id: UUID | str) -> list[GroupAssignment]

Fetch the user's group assignments.

:param id: User UUID as a UUID or UUID string. :returns: A validated list of GroupAssignment objects.

Source code in qlam_core/plugins/users/api/client.py
386
387
388
389
390
391
392
393
394
395
396
def get_groups(self, id: UUID | str) -> list[GroupAssignment]:  # noqa: A002
    """Fetch the user's group assignments.

    :param id: User UUID as a ``UUID`` or UUID string.
    :returns: A validated list of ``GroupAssignment`` objects.
    """
    response = self._execute(
        "get_user_groups",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return list(USER_GROUP_ASSIGNMENTS_ADAPTER.validate_python(response))

get_roles

get_roles(id: UUID | str) -> list[RoleAssignment]

Fetch the user's role assignments.

:param id: User UUID as a UUID or UUID string. :returns: A validated list of RoleAssignment objects.

Source code in qlam_core/plugins/users/api/client.py
374
375
376
377
378
379
380
381
382
383
384
def get_roles(self, id: UUID | str) -> list[RoleAssignment]:  # noqa: A002
    """Fetch the user's role assignments.

    :param id: User UUID as a ``UUID`` or UUID string.
    :returns: A validated list of ``RoleAssignment`` objects.
    """
    response = self._execute(
        "get_user_roles",
        uuid=str(id) if isinstance(id, UUID) else id,
    )
    return list(USER_ROLE_ASSIGNMENTS_ADAPTER.validate_python(response))

iter_pages

iter_pages(start_page: int = 0, size: int | None = None, sort: str | None = DEFAULT_USER_SORT_ORDER, tenant_id: UUID | str | None = None, id: list[UUID | str] | None = None, name: list[str] | None = None, email: list[str] | None = None, auth_provider: list[str] | None = None, group_id: list[UUID | str] | None = None, max_pages: int | None = None) -> Iterator[Page[UserResponse]]

Yield user pages lazily.

Use this when you want to stream through paginated results without collecting every user in memory up front.

:param start_page: Zero-based page index to start from. :param size: Optional page size. :param sort: Optional sort expression applied to every fetched page. :param tenant_id: Optional tenant UUID filter applied to every page. :param id: Optional user UUID filters applied to every page. :param name: Optional name filters applied to every page. :param email: Optional email filters applied to every page. :param auth_provider: Optional auth provider filters applied to every page. :param group_id: Optional group UUID filters applied to every page. :param max_pages: Optional maximum number of pages to yield. :returns: An iterator of typed user pages.

Source code in qlam_core/plugins/users/api/client.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def iter_pages(
    self,
    start_page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_USER_SORT_ORDER,
    tenant_id: UUID | str | None = None,
    id: list[UUID | str] | None = None,  # noqa: A002
    name: list[str] | None = None,
    email: list[str] | None = None,
    auth_provider: list[str] | None = None,
    group_id: list[UUID | str] | None = None,
    max_pages: int | None = None,
) -> Iterator[Page[UserResponse]]:
    """Yield user pages lazily.

    Use this when you want to stream through paginated results without
    collecting every user in memory up front.

    :param start_page: Zero-based page index to start from.
    :param size: Optional page size.
    :param sort: Optional sort expression applied to every fetched page.
    :param tenant_id: Optional tenant UUID filter applied to every page.
    :param id: Optional user UUID filters applied to every page.
    :param name: Optional name filters applied to every page.
    :param email: Optional email filters applied to every page.
    :param auth_provider: Optional auth provider filters applied to every page.
    :param group_id: Optional group UUID filters applied to every page.
    :param max_pages: Optional maximum number of pages to yield.
    :returns: An iterator of typed user pages.
    """
    current_page = start_page
    fetched_pages = 0

    while True:
        if max_pages is not None and fetched_pages >= max_pages:
            break

        page_result = self.list_page(
            page=current_page,
            size=size,
            sort=sort,
            tenant_id=tenant_id,
            id=id,
            name=name,
            email=email,
            auth_provider=auth_provider,
            group_id=group_id,
        )
        if not page_result.items:
            break

        yield page_result
        fetched_pages += 1

        if not page_result.has_next:
            break

        current_page += 1

list

list(page: int = 0, size: int | None = None, sort: str | None = DEFAULT_USER_SORT_ORDER, tenant_id: UUID | str | None = None, id: list[UUID | str] | None = None, name: list[str] | None = None, email: list[str] | None = None, auth_provider: list[str] | None = None, group_id: list[UUID | str] | None = None) -> list[UserResponse]

Return users from a single page.

This is a convenience wrapper around :meth:list_page that returns only the page items.

Filter parameters match :meth:list_page.

Source code in qlam_core/plugins/users/api/client.py
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def list(
    self,
    page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_USER_SORT_ORDER,
    tenant_id: UUID | str | None = None,
    id: list[UUID | str] | None = None,  # noqa: A002
    name: list[str] | None = None,
    email: list[str] | None = None,
    auth_provider: list[str] | None = None,
    group_id: list[UUID | str] | None = None,
) -> list[UserResponse]:
    """Return users from a single page.

    This is a convenience wrapper around :meth:`list_page` that returns
    only the page items.

    Filter parameters match :meth:`list_page`.
    """
    return self.list_page(
        page=page,
        size=size,
        sort=sort,
        tenant_id=tenant_id,
        id=id,
        name=name,
        email=email,
        auth_provider=auth_provider,
        group_id=group_id,
    ).items

list_all

list_all(size: int | None = None, sort: str | None = DEFAULT_USER_SORT_ORDER, tenant_id: UUID | str | None = None, id: list[UUID | str] | None = None, name: list[str] | None = None, email: list[str] | None = None, auth_provider: list[str] | None = None, group_id: list[UUID | str] | None = None, max_items: int | None = None) -> list[UserResponse]

Return users across all pages.

This eagerly collects items from :meth:iter_pages into a single list.

:param size: Optional page size. :param sort: Optional sort expression applied to every fetched page. :param tenant_id: Optional tenant UUID filter. :param id: Optional user UUID filters. :param name: Optional name filters. :param email: Optional email filters. :param auth_provider: Optional auth provider filters. :param group_id: Optional group UUID filters. :param max_items: Optional cap on the total number of items returned. :returns: A list of UserResponse objects.

Source code in qlam_core/plugins/users/api/client.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
def list_all(
    self,
    size: int | None = None,
    sort: str | None = DEFAULT_USER_SORT_ORDER,
    tenant_id: UUID | str | None = None,
    id: list[UUID | str] | None = None,  # noqa: A002
    name: list[str] | None = None,
    email: list[str] | None = None,
    auth_provider: list[str] | None = None,
    group_id: list[UUID | str] | None = None,
    max_items: int | None = None,
) -> list[UserResponse]:
    """Return users across all pages.

    This eagerly collects items from :meth:`iter_pages` into a single list.

    :param size: Optional page size.
    :param sort: Optional sort expression applied to every fetched page.
    :param tenant_id: Optional tenant UUID filter.
    :param id: Optional user UUID filters.
    :param name: Optional name filters.
    :param email: Optional email filters.
    :param auth_provider: Optional auth provider filters.
    :param group_id: Optional group UUID filters.
    :param max_items: Optional cap on the total number of items returned.
    :returns: A list of ``UserResponse`` objects.
    """
    if max_items == 0:
        return []

    items: list[UserResponse] = []
    for page_result in self.iter_pages(
        size=size,
        sort=sort,
        tenant_id=tenant_id,
        id=id,
        name=name,
        email=email,
        auth_provider=auth_provider,
        group_id=group_id,
    ):
        items.extend(page_result.items)
        if max_items is not None and len(items) >= max_items:
            return items[:max_items]

    return items

list_page

list_page(page: int = 0, size: int | None = None, sort: str | None = DEFAULT_USER_SORT_ORDER, tenant_id: UUID | str | None = None, id: list[UUID | str] | None = None, name: list[str] | None = None, email: list[str] | None = None, auth_provider: list[str] | None = None, group_id: list[UUID | str] | None = None) -> Page[UserResponse]

Return one page of users.

:param page: Zero-based page index. :param size: Optional page size. If omitted, the server default is used. :param sort: Optional sort expression. Defaults to created_date,DESC. :param tenant_id: Optional tenant UUID filter. :param id: Optional user UUID filters. Repeated values are ORed. :param name: Optional name filters using contains-style wildcard search. :param email: Optional email filters using exact match. :param auth_provider: Optional auth provider filters using exact match. :param group_id: Optional group UUID filters. Repeated values are ORed. :returns: A typed page of UserResponse items.

Source code in qlam_core/plugins/users/api/client.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def list_page(
    self,
    page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_USER_SORT_ORDER,
    tenant_id: UUID | str | None = None,
    id: list[UUID | str] | None = None,  # noqa: A002
    name: list[str] | None = None,
    email: list[str] | None = None,
    auth_provider: list[str] | None = None,
    group_id: list[UUID | str] | None = None,
) -> Page[UserResponse]:
    """Return one page of users.

    :param page: Zero-based page index.
    :param size: Optional page size. If omitted, the server default is used.
    :param sort: Optional sort expression. Defaults to ``created_date,DESC``.
    :param tenant_id: Optional tenant UUID filter.
    :param id: Optional user UUID filters. Repeated values are ORed.
    :param name: Optional name filters using contains-style wildcard search.
    :param email: Optional email filters using exact match.
    :param auth_provider: Optional auth provider filters using exact match.
    :param group_id: Optional group UUID filters. Repeated values are ORed.
    :returns: A typed page of ``UserResponse`` items.
    """
    response = self._execute(
        "list_users",
        **_build_list_users_params(
            page=page,
            size=size,
            sort=sort,
            tenant_id=tenant_id,
            id=id,
            name=name,
            email=email,
            auth_provider=auth_provider,
            group_id=group_id,
        ),
    )
    parsed = PageUserResponse.model_validate(response)
    return Page(
        items=list(parsed.elements),
        page_number=parsed.page,
        page_size=parsed.size,
        total_items=parsed.total,
    )

set_roles

set_roles(id: UUID | str, roles: list[RoleAssignment] | list[dict[str, object]]) -> list[RoleAssignment]

Replace the user's role assignments with a bare JSON list body.

:param id: User UUID as a UUID or UUID string. :param roles: A list of validated role models or JSON-like dictionaries. :returns: The updated list of RoleAssignment objects.

Source code in qlam_core/plugins/users/api/client.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def set_roles(
    self,
    id: UUID | str,  # noqa: A002
    roles: list[RoleAssignment] | list[dict[str, object]],
) -> list[RoleAssignment]:
    """Replace the user's role assignments with a bare JSON list body.

    :param id: User UUID as a ``UUID`` or UUID string.
    :param roles: A list of validated role models or JSON-like dictionaries.
    :returns: The updated list of ``RoleAssignment`` objects.
    """
    response = self._execute(
        "set_user_roles",
        uuid=str(id) if isinstance(id, UUID) else id,
        data=[
            (
                role.model_dump(mode="json", exclude_none=True)
                if isinstance(role, RoleAssignment)
                else role
            )
            for role in roles
        ],
    )
    return list(USER_ROLE_ASSIGNMENTS_ADAPTER.validate_python(response))

update

update(id: UUID | str, body: PatchUserRequest | dict[str, object]) -> UserResponse

Patch user profile fields.

:param id: User UUID as a UUID or UUID string. :param body: A validated patch model or a JSON-like dictionary. :returns: The updated user as a UserResponse.

Source code in qlam_core/plugins/users/api/client.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
def update(
    self,
    id: UUID | str,  # noqa: A002
    body: PatchUserRequest | dict[str, object],
) -> UserResponse:
    """Patch user profile fields.

    :param id: User UUID as a ``UUID`` or UUID string.
    :param body: A validated patch model or a JSON-like dictionary.
    :returns: The updated user as a ``UserResponse``.
    """
    response = self._execute(
        "patch_user",
        uuid=str(id) if isinstance(id, UUID) else id,
        data=(
            body.model_dump(mode="json", exclude_none=True)
            if isinstance(body, PatchUserRequest)
            else body
        ),
    )
    return UserResponse.model_validate(response)

Groups Client

Groups Client - Clean Python API for group management.

This module provides a typed, presentation-free API for group lifecycle and membership management. It talks to the non-QPU-scoped groups service and returns strongly-typed Pydantic models.

Usage
from qlam_core.common.context import AppContext
from qlam_core.plugins.groups import GroupsClient

ctx = AppContext()

with GroupsClient(ctx) as client:
    page = client.list_page(size=25)
    group = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
    members = client.list_users(id=group.id)

GroupsClient

GroupsClient(ctx: AppContext)

Bases: BaseRestApiWithoutQpuMode


              flowchart TD
              qlam_core.plugins.groups.api.client.GroupsClient[GroupsClient]
              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode[BaseRestApiWithoutQpuMode]

                              qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode --> qlam_core.plugins.groups.api.client.GroupsClient
                


              click qlam_core.plugins.groups.api.client.GroupsClient href "" "qlam_core.plugins.groups.api.client.GroupsClient"
              click qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode href "" "qlam_core.sdk.base_api.BaseRestApiWithoutQpuMode"
            

Typed API for group and group-membership operations.

This client provides explicit methods for listing, creating, updating, and deleting groups, plus reading and mutating group membership.

Unlike QPU-scoped clients such as TasksClient, this client targets the groups service and therefore does not accept or resolve qpu_mode. Private visibility is allowed so list/get can rewrite to the private path; private create/update/delete and membership are unsupported server-side.

Example
client = GroupsClient(ctx)

page = client.list_page(page=0, size=50)
group = client.get(id="a1b2c3d4-e5f6-7890-abcd-ef1234567890")
members = client.list_users(id=group.id)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/groups/api/client.py
71
72
73
74
75
76
def __init__(self, ctx: AppContext):
    """Initialize the groups API.

    :param ctx: Application context with configuration and auth.
    """
    super().__init__(ctx, resource="groups")

add_users

add_users(id: UUID | str, body: GroupMemberRequest | dict[str, object]) -> None

Add users to a group.

The underlying endpoint returns HTTP 204 with no response body on success, so this method returns None.

:param id: Group UUID as a UUID or UUID string. :param body: A validated membership request or a JSON-like dictionary shaped as {"users": [...]}.

Source code in qlam_core/plugins/groups/api/client.py
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
def add_users(
    self,
    id: UUID | str,  # noqa: A002
    body: GroupMemberRequest | dict[str, object],
) -> None:
    """Add users to a group.

    The underlying endpoint returns HTTP 204 with no response body on
    success, so this method returns ``None``.

    :param id: Group UUID as a ``UUID`` or UUID string.
    :param body: A validated membership request or a JSON-like dictionary
        shaped as ``{"users": [...]}``.
    """
    request = (
        GroupMemberRequest.model_validate(body) if isinstance(body, dict) else body
    )
    self._execute(
        "addgroupusers",
        id=str(id) if isinstance(id, UUID) else id,
        data=request.model_dump(
            mode="json",
            exclude_none=True,
            include=set(GroupMemberRequest.model_fields),
        ),
    )

create

create(body: GroupRequest | dict[str, object]) -> GroupResponse

Create a group.

:param body: A validated request model or a JSON-like dictionary. :returns: The created group as a GroupResponse.

Source code in qlam_core/plugins/groups/api/client.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
def create(self, body: GroupRequest | dict[str, object]) -> GroupResponse:
    """Create a group.

    :param body: A validated request model or a JSON-like dictionary.
    :returns: The created group as a ``GroupResponse``.
    """
    request = GroupRequest.model_validate(body) if isinstance(body, dict) else body
    response = self._execute(
        "create",
        data=request.model_dump(
            mode="json",
            exclude_none=True,
            include=set(GroupRequest.model_fields),
        ),
    )
    return GroupResponse.model_validate(response)

delete

delete(id: UUID | str) -> None

Delete (deactivate) a group.

The underlying endpoint returns HTTP 204 with no response body on success, so this method returns None.

:param id: Group UUID as a UUID or UUID string.

Source code in qlam_core/plugins/groups/api/client.py
340
341
342
343
344
345
346
347
348
349
350
351
def delete(self, id: UUID | str) -> None:  # noqa: A002
    """Delete (deactivate) a group.

    The underlying endpoint returns HTTP 204 with no response body on
    success, so this method returns ``None``.

    :param id: Group UUID as a ``UUID`` or UUID string.
    """
    self._execute(
        "delete",
        id=str(id) if isinstance(id, UUID) else id,
    )

get

get(id: UUID | str) -> GroupResponse

Fetch one group by UUID.

:param id: Group UUID as a UUID or UUID string. :returns: The validated group response model.

Source code in qlam_core/plugins/groups/api/client.py
288
289
290
291
292
293
294
295
296
297
298
def get(self, id: UUID | str) -> GroupResponse:  # noqa: A002
    """Fetch one group by UUID.

    :param id: Group UUID as a ``UUID`` or UUID string.
    :returns: The validated group response model.
    """
    response = self._execute(
        "getgroup",
        id=str(id) if isinstance(id, UUID) else id,
    )
    return GroupResponse.model_validate(response)

iter_pages

iter_pages(start_page: int = 0, size: int | None = None, sort: str | None = DEFAULT_GROUP_SORT_ORDER, name: list[str] | None = None, is_shared: bool | None = None, max_pages: int | None = None, id: UUID | str | Sequence[UUID | str] | None = None) -> Iterator[Page[GroupResponse]]

Yield group pages lazily.

Use this when you want to stream through paginated results without collecting every group in memory up front.

:param start_page: Zero-based page index to start from. :param size: Optional page size. :param sort: Optional sort expression applied to every fetched page. :param name: Optional name filters applied to every page. :param is_shared: Optional shared-group filter applied to every page. :param max_pages: Optional maximum number of pages to yield. :param id: Optional group UUID filter or filters applied to every page. :returns: An iterator of typed group pages.

Source code in qlam_core/plugins/groups/api/client.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def iter_pages(
    self,
    start_page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_GROUP_SORT_ORDER,
    name: list[str] | None = None,
    is_shared: bool | None = None,
    max_pages: int | None = None,
    id: UUID | str | Sequence[UUID | str] | None = None,  # noqa: A002
) -> Iterator[Page[GroupResponse]]:
    """Yield group pages lazily.

    Use this when you want to stream through paginated results without
    collecting every group in memory up front.

    :param start_page: Zero-based page index to start from.
    :param size: Optional page size.
    :param sort: Optional sort expression applied to every fetched page.
    :param name: Optional name filters applied to every page.
    :param is_shared: Optional shared-group filter applied to every page.
    :param max_pages: Optional maximum number of pages to yield.
    :param id: Optional group UUID filter or filters applied to every page.
    :returns: An iterator of typed group pages.
    """
    current_page = start_page
    fetched_pages = 0
    effective_size = size

    while True:
        if max_pages is not None and fetched_pages >= max_pages:
            break

        page_result = self.list_page(
            page=current_page,
            size=effective_size,
            sort=sort,
            id=id,
            name=name,
            is_shared=is_shared,
        )
        if not page_result.items:
            break

        yield page_result
        fetched_pages += 1

        # Lock inferred size after the first page so has_next stays accurate
        # when PageGroup omits a size field.
        if effective_size is None:
            effective_size = page_result.page_size

        if not page_result.has_next:
            break

        current_page += 1

list

list(page: int = 0, size: int | None = None, sort: str | None = DEFAULT_GROUP_SORT_ORDER, name: list[str] | None = None, is_shared: bool | None = None, id: UUID | str | Sequence[UUID | str] | None = None) -> list[GroupResponse]

Return groups from a single page.

This is a convenience wrapper around :meth:list_page that returns only the page items.

Filter parameters match :meth:list_page.

Source code in qlam_core/plugins/groups/api/client.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def list(
    self,
    page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_GROUP_SORT_ORDER,
    name: list[str] | None = None,
    is_shared: bool | None = None,
    id: UUID | str | Sequence[UUID | str] | None = None,  # noqa: A002
) -> list[GroupResponse]:
    """Return groups from a single page.

    This is a convenience wrapper around :meth:`list_page` that returns
    only the page items.

    Filter parameters match :meth:`list_page`.
    """
    return self.list_page(
        page=page,
        size=size,
        sort=sort,
        id=id,
        name=name,
        is_shared=is_shared,
    ).items

list_all

list_all(size: int | None = None, sort: str | None = DEFAULT_GROUP_SORT_ORDER, name: list[str] | None = None, is_shared: bool | None = None, max_items: int | None = None, id: UUID | str | Sequence[UUID | str] | None = None) -> list[GroupResponse]

Return groups across all pages.

This eagerly collects items from :meth:iter_pages into a single list.

:param size: Optional page size. :param sort: Optional sort expression applied to every fetched page. :param name: Optional name filters applied to every page. :param is_shared: Optional shared-group filter applied to every page. :param max_items: Optional cap on the total number of items returned. :param id: Optional group UUID filter or filters applied to every page. :returns: A list of GroupResponse objects.

Source code in qlam_core/plugins/groups/api/client.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def list_all(
    self,
    size: int | None = None,
    sort: str | None = DEFAULT_GROUP_SORT_ORDER,
    name: list[str] | None = None,
    is_shared: bool | None = None,
    max_items: int | None = None,
    id: UUID | str | Sequence[UUID | str] | None = None,  # noqa: A002
) -> list[GroupResponse]:
    """Return groups across all pages.

    This eagerly collects items from :meth:`iter_pages` into a single list.

    :param size: Optional page size.
    :param sort: Optional sort expression applied to every fetched page.
    :param name: Optional name filters applied to every page.
    :param is_shared: Optional shared-group filter applied to every page.
    :param max_items: Optional cap on the total number of items returned.
    :param id: Optional group UUID filter or filters applied to every page.
    :returns: A list of ``GroupResponse`` objects.
    """
    if max_items == 0:
        return []

    items: list[GroupResponse] = []
    for page_result in self.iter_pages(
        size=size, sort=sort, id=id, name=name, is_shared=is_shared
    ):
        items.extend(page_result.items)
        if max_items is not None and len(items) >= max_items:
            return items[:max_items]

    return items

list_page

list_page(page: int = 0, size: int | None = None, sort: str | None = DEFAULT_GROUP_SORT_ORDER, name: list[str] | None = None, is_shared: bool | None = None, id: UUID | str | Sequence[UUID | str] | None = None) -> Page[GroupResponse]

Return one page of groups.

:param page: Zero-based page index. :param size: Optional page size. If omitted, the server default is used. :param sort: Optional sort expression. Defaults to created_date,desc. :param name: Optional name filters using case-insensitive contains matching. Repeated values are ORed. :param is_shared: Optional shared-group filter. :param id: Optional group UUID filter or filters. Repeated values are ORed. :returns: A typed page of GroupResponse items.

Source code in qlam_core/plugins/groups/api/client.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def list_page(
    self,
    page: int = 0,
    size: int | None = None,
    sort: str | None = DEFAULT_GROUP_SORT_ORDER,
    name: list[str] | None = None,
    is_shared: bool | None = None,
    id: UUID | str | Sequence[UUID | str] | None = None,  # noqa: A002
) -> Page[GroupResponse]:
    """Return one page of groups.

    :param page: Zero-based page index.
    :param size: Optional page size. If omitted, the server default is used.
    :param sort: Optional sort expression. Defaults to ``created_date,desc``.
    :param name: Optional name filters using case-insensitive contains
        matching. Repeated values are ORed.
    :param is_shared: Optional shared-group filter.
    :param id: Optional group UUID filter or filters. Repeated values are ORed.
    :returns: A typed page of ``GroupResponse`` items.
    """
    id_values = [id] if isinstance(id, (UUID, str)) else id
    response = self._execute(
        "getallgroups",
        page=page,
        size=size,
        sort=sort,
        id=(
            None
            if id_values is None
            else [
                str(value) if isinstance(value, UUID) else value
                for value in id_values
            ]
        ),
        name=name,
        isShared=is_shared,
    )
    # PageGroup omits size; prefer the request size, then any wire size,
    # then the documented server default. Never infer from len(elements):
    # a partial final page would understate the page size and corrupt
    # has_next, and iter_pages would then re-request earlier records.
    wire_size = response.get("size") if isinstance(response, dict) else None
    parsed = PageGroup.model_validate(response)
    if size is not None:
        page_size = size
    elif isinstance(wire_size, int) and wire_size > 0:
        page_size = wire_size
    else:
        page_size = DEFAULT_GROUP_PAGE_SIZE
    return Page(
        items=list(parsed.elements),
        page_number=parsed.page,
        page_size=page_size,
        total_items=parsed.total,
    )

list_users

list_users(id: UUID | str, page: int = 0, size: int | None = None) -> list[UserResponse]

Return group members for one requested page.

GET /v2/groups/{id}/users returns GroupMemberResponse with a bare users list and no page metadata. This method returns that list for the requested page/size only.

:param id: Group UUID as a UUID or UUID string. :param page: Zero-based page index passed to the API. :param size: Optional page size passed to the API. :returns: A list of UserResponse members for the requested page.

Source code in qlam_core/plugins/groups/api/client.py
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
def list_users(
    self,
    id: UUID | str,  # noqa: A002
    page: int = 0,
    size: int | None = None,
) -> list[UserResponse]:
    """Return group members for one requested page.

    ``GET /v2/groups/{id}/users`` returns ``GroupMemberResponse`` with a
    bare ``users`` list and **no** page metadata. This method returns that
    list for the requested ``page``/``size`` only.

    :param id: Group UUID as a ``UUID`` or UUID string.
    :param page: Zero-based page index passed to the API.
    :param size: Optional page size passed to the API.
    :returns: A list of ``UserResponse`` members for the requested page.
    """
    response = self._execute(
        "getgroupusers",
        id=str(id) if isinstance(id, UUID) else id,
        page=page,
        size=size,
    )
    parsed = GroupMemberResponse.model_validate(response)
    return list(parsed.users)

remove_user

remove_user(id: UUID | str, user_id: UUID | str) -> None

Remove a user from a group.

The underlying endpoint returns HTTP 204 with no response body on success, so this method returns None.

:param id: Group UUID as a UUID or UUID string. :param user_id: User UUID as a UUID or UUID string.

Source code in qlam_core/plugins/groups/api/client.py
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
def remove_user(
    self,
    id: UUID | str,  # noqa: A002
    user_id: UUID | str,
) -> None:
    """Remove a user from a group.

    The underlying endpoint returns HTTP 204 with no response body on
    success, so this method returns ``None``.

    :param id: Group UUID as a ``UUID`` or UUID string.
    :param user_id: User UUID as a ``UUID`` or UUID string.
    """
    self._execute(
        "removegroupuser",
        id=str(id) if isinstance(id, UUID) else id,
        userId=str(user_id) if isinstance(user_id, UUID) else user_id,
    )

resolve_id

resolve_id(group: UUID | str) -> UUID

Resolve a group reference (UUID or exact name) to the group UUID.

A UUID-shaped reference is returned as-is without a lookup; the two input spaces cannot overlap because group names are capped at 30 characters while a canonical UUID string has 36. Anything else is treated as a group name: the server narrows candidates with its case-insensitive contains-matching name filter and this method picks the case-insensitive exact match. Active group names are unique per tenant, so at most one exact match exists.

:param group: Group UUID (or UUID string), or exact group name. :returns: The resolved group UUID. :raises ValidationError: If no group has the given name.

Source code in qlam_core/plugins/groups/api/client.py
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
def resolve_id(self, group: UUID | str) -> UUID:
    """Resolve a group reference (UUID or exact name) to the group UUID.

    A UUID-shaped reference is returned as-is without a lookup; the two
    input spaces cannot overlap because group names are capped at 30
    characters while a canonical UUID string has 36. Anything else is
    treated as a group name: the server narrows candidates with its
    case-insensitive contains-matching ``name`` filter and this method
    picks the case-insensitive exact match. Active group names are
    unique per tenant, so at most one exact match exists.

    :param group: Group UUID (or UUID string), or exact group name.
    :returns: The resolved group UUID.
    :raises ValidationError: If no group has the given name.
    """
    if isinstance(group, UUID):
        return group
    try:
        return UUID(group)
    except ValueError:
        pass

    needle = group.casefold()
    near_misses: list[str] = []
    for page_result in self.iter_pages(name=[group]):
        for item in page_result.items:
            if item.name.casefold() == needle:
                return item.id
            near_misses.append(item.name)

    message = f"No group named {group!r}."
    closest = sorted(set(near_misses))[:5]
    if closest:
        message += f" Closest matches: {', '.join(closest)}."
    raise ValidationError(message)

update

update(id: UUID | str, body: GroupRequest | dict[str, object]) -> GroupResponse

Update a group.

:param id: Group UUID as a UUID or UUID string. :param body: A validated request model or a JSON-like dictionary. :returns: The updated group as a GroupResponse.

Source code in qlam_core/plugins/groups/api/client.py
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def update(
    self,
    id: UUID | str,  # noqa: A002
    body: GroupRequest | dict[str, object],
) -> GroupResponse:
    """Update a group.

    :param id: Group UUID as a ``UUID`` or UUID string.
    :param body: A validated request model or a JSON-like dictionary.
    :returns: The updated group as a ``GroupResponse``.
    """
    request = GroupRequest.model_validate(body) if isinstance(body, dict) else body
    response = self._execute(
        "update",
        id=str(id) if isinstance(id, UUID) else id,
        data=request.model_dump(
            mode="json",
            exclude_none=True,
            include=set(GroupRequest.model_fields),
        ),
    )
    return GroupResponse.model_validate(response)