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, and user role 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)

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)

:param ctx: Application context with configuration and auth.

Source code in qlam_core/plugins/users/api/client.py
 99
100
101
102
103
104
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
383
384
385
386
387
388
389
390
391
392
393
394
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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
285
286
287
288
289
290
291
292
293
294
295
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
336
337
338
339
340
341
342
343
344
345
346
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_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
348
349
350
351
352
353
354
355
356
357
358
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, 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 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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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,
    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 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,
        )
        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) -> 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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,
) -> 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,
    ).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, 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 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
241
242
243
244
245
246
247
248
249
250
251
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
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,
    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 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,
    ):
        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) -> 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. :returns: A typed page of UserResponse items.

Source code in qlam_core/plugins/users/api/client.py
112
113
114
115
116
117
118
119
120
121
122
123
124
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
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,
) -> 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.
    :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,
        ),
    )
    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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
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)