Label Templates
albert.collections.label_templates.LabelTemplateCollection
Bases: BaseCollection
Manage Label Templates in the Albert platform.
A label template pairs a tenant-scoped Mustache HTML file with page
rendering options, and drives printable outputs such as inventory lot
barcode labels, batch task labels, and formula reports. Label Template
IDs use the TMP prefix.
Printing a label is a two-step flow: get_print_payload
assembles the label data for an entity (for example a Lot), and
generate_pdf
renders it to a stored PDF. Use generate_label_pdf
to run both steps in one call.
This collection is accessed as client.label_templates.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for label template requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new label template, optionally uploading its HTML files. |
get_by_id |
Get a single label template by its ID. |
get_all |
Get all label templates, with optional filters. |
update |
Update an existing label template. |
delete |
Delete a label template by its ID. |
get_print_payload |
Assemble the render payload for printing a label. |
generate_label_pdf |
Generate a label PDF for a Lot and return its download URL. |
get_batch_label_url |
Generate a hazard batch label PDF for a batch task. |
get_formula_report_url |
Generate a formula report PDF. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/label_templates.py
create
create(
*,
label_template: LabelTemplate,
template_html: str | bytes | None = None,
header_html: str | bytes | None = None,
footer_html: str | bytes | None = None,
) -> LabelTemplate
Create a new label template.
When HTML content is provided, it is uploaded and stored for the
tenant alongside the new template. template_html is stored under
the template_file name, and header_html / footer_html are
stored under the header / footer file names from the
template's metadata. Without HTML content, the template record is
created pointing at an already-stored template_file.
The HTML file is a complete, ordinary HTML document whose body is
wrapped in a {{#labels}} ... {{/labels}} section, with Mustache
placeholders that are filled from the print payload for the
template's type. Inventory label templates, for example, can use
{{info.inventoryName}}, {{info.vendorLotNumber}},
{{info.expirationDate}}, {{{info.lotNumber}}} (barcode
image), {{{info.lotNumberQrCode}}} (QR image),
{{#info.Symbols}} (hazard pictograms), and the full records under
{{info.AdditionalInfo...}}, plus {{manualFields.<Name>}} for
user-entered values. The complete per-type field reference is on the
Label Templates page in the docs Examples section; to see exactly
what a template will receive, call get_print_payload
and inspect payload.data["labels"].
Example
from pathlib import Path
from albert.resources.label_templates import LabelTemplate, LabelTemplateType
template = LabelTemplate(
name="3x1 Inventory Label",
type=LabelTemplateType.INVENTORY,
template_file="3x1-inventory-label.html",
metadata={"width": "3in", "height": "1in"},
)
created = client.label_templates.create(
label_template=template,
template_html=Path("3x1-inventory-label.html").read_text(),
)
created.id
# 'TMP123'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_template
|
LabelTemplate
|
The label template to create. |
required |
template_html
|
str or bytes
|
The Mustache HTML content for the template body. Stored under the
|
None
|
header_html
|
str or bytes
|
The Mustache HTML content for the page header. Stored under the
|
None
|
footer_html
|
str or bytes
|
The Mustache HTML content for the page footer. Stored under the
|
None
|
Returns:
| Type | Description |
|---|---|
LabelTemplate
|
The newly created label template, fully populated. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If HTML content is provided without a corresponding file name on the template. |
Source code in src/albert/collections/label_templates.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 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 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 | |
get_by_id
get_by_id(*, id: LabelTemplateId) -> LabelTemplate
Get a label template by its ID.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
LabelTemplateId
|
The Label Template ID (format |
required |
Returns:
| Type | Description |
|---|---|
LabelTemplate
|
The fully populated LabelTemplate. |
Source code in src/albert/collections/label_templates.py
get_all
get_all(
*,
name: str | None = None,
type: LabelTemplateType
| list[LabelTemplateType]
| None = None,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[LabelTemplate]
Get all label templates, with optional filters.
Results are returned as a lazily paginated iterator.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Filter templates by name. |
None
|
type
|
LabelTemplateType or list[LabelTemplateType]
|
Filter templates by type (e.g. |
None
|
start_key
|
str
|
Provide the |
None
|
max_items
|
int
|
Maximum number of items to return in total. If None, iterates over all matches. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[LabelTemplate]
|
A lazily paginated iterator of matching label templates. |
Source code in src/albert/collections/label_templates.py
update
update(*, label_template: LabelTemplate) -> LabelTemplate
Update an existing label template.
Fetch a template (e.g. via get_by_id), modify the updatable
fields on the returned object, then pass it here. The template is
matched by its id.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_template
|
LabelTemplate
|
The label template to update. Its |
required |
Returns:
| Type | Description |
|---|---|
LabelTemplate
|
The updated LabelTemplate. |
Notes
The following fields can be updated: default, metadata,
name, template_file.
Source code in src/albert/collections/label_templates.py
delete
delete(*, id: LabelTemplateId) -> None
Delete a label template by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
LabelTemplateId
|
The Label Template ID to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/label_templates.py
get_print_payload
get_print_payload(
*,
type: LabelTemplateType = INVENTORY,
inventory_lot_number_id: LotId
| list[LotId]
| None = None,
albert_id: InventoryId | None = None,
task_id: TaskId | None = None,
lot_id: str | None = None,
block_id: BlockId | None = None,
template_id: LabelTemplateId | None = None,
jurisdiction: str | None = None,
) -> LabelPrintPayload
Assemble the render payload for printing a label.
Gathers everything needed to render the label for the given entity:
the resolved template file URLs (payload.template.body is the URL
of the tenant's Mustache HTML file), the per-entity label data
(including barcode and QR code images), page options, and the storage
destination. Pass the payload fields to
generate_pdf
to render the PDF, or use generate_label_pdf
to do both steps in one call.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
LabelTemplateType
|
The kind of label to assemble. Defaults to |
INVENTORY
|
inventory_lot_number_id
|
LotId or list[LotId]
|
The Lot ID(s) to print (format |
None
|
albert_id
|
InventoryId
|
The Inventory ID (format |
None
|
task_id
|
TaskId
|
The Task ID (format |
None
|
lot_id
|
str
|
Restrict property task labels to a specific lot. |
None
|
block_id
|
BlockId
|
Restrict property task labels to a specific block (format
|
None
|
template_id
|
LabelTemplateId
|
The Label Template ID to render with (format |
None
|
jurisdiction
|
str
|
The jurisdiction used to select hazard pictograms. |
None
|
Returns:
| Type | Description |
|---|---|
LabelPrintPayload
|
The assembled label render payload. |
Source code in src/albert/collections/label_templates.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
generate_label_pdf
generate_label_pdf(
*,
inventory_lot_number_id: LotId | list[LotId],
template_id: LabelTemplateId | None = None,
jurisdiction: str | None = None,
) -> str
Generate a barcode label PDF for one or more Lots.
Assembles the label data for the given Lot(s) and renders it to a
stored PDF using the given template (or the tenant default). This is
the one-call equivalent of get_print_payload
followed by generate_pdf.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inventory_lot_number_id
|
LotId or list[LotId]
|
The Lot ID(s) to print (format |
required |
template_id
|
LabelTemplateId
|
The Label Template ID to render with (format |
None
|
jurisdiction
|
str
|
The jurisdiction used to select hazard pictograms. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived URL for downloading the generated label PDF. |
Source code in src/albert/collections/label_templates.py
get_batch_label_url
Generate a hazard batch label PDF for a batch task.
Renders the GHS-style batch label (hazard pictograms, signal word, hazard and precautionary statements) for the formulas on a batch task and returns a short-lived URL for the finished PDF. This label type is rendered by the platform's document generator rather than from a tenant label template file.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
TaskId
|
The batch Task ID (format |
required |
lot_id
|
str
|
A specific lot number to print, when the task produced multiple lots. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived URL for downloading the generated batch label PDF. |
Source code in src/albert/collections/label_templates.py
get_formula_report_url
get_formula_report_url(
*,
formula_id: InventoryId,
template_id: LabelTemplateId | None = None,
lot_id: str | None = None,
) -> str
Generate a formula report PDF.
Renders a full report for a formula (composition, property task
results, and related details) using a formulareport template and
returns a short-lived URL for the finished PDF.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula_id
|
InventoryId
|
The formula Inventory ID (format |
required |
template_id
|
LabelTemplateId
|
The |
None
|
lot_id
|
str
|
Restrict the report to a specific lot. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A short-lived URL for downloading the generated report PDF. |