Skip to content

Report Templates

albert.collections.report_templates.ReportTemplateCollection

ReportTemplateCollection(*, session: AlbertSession)

Bases: BaseCollection

Manage Report Templates in the Albert platform.

A Report Template defines a reusable report configuration: the report type it is based on, its available filters, and its default column, chart, and metadata state. Templates are the catalog of report types that can be run via ReportCollection. Each template belongs to a ReportTemplateCategory (analytics, datascience, or reports).

This collection is read-only: it retrieves and lists existing templates.

This collection is accessed as client.report_templates.

Example

from albert import Albert
from albert.resources.report_templates import ReportTemplateCategory

client = Albert()
templates = client.report_templates.get_all(
    category=ReportTemplateCategory.ANALYTICS
)
for template in templates:
    print(template.id, template.name)

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 report template requests.

Methods:

Name Description
get_by_id

Get a single report template by its ID.

get_all

List all report templates, optionally filtered by category.

Parameters:

Name Type Description Default
session AlbertSession

The authenticated Albert session used for API calls.

required
Source code in src/albert/collections/report_templates.py
def __init__(self, *, session: AlbertSession):
    """Initialize a ReportTemplateCollection.

    Parameters
    ----------
    session : AlbertSession
        The authenticated Albert session used for API calls.
    """
    super().__init__(session=session)
    self.base_path = f"/api/{ReportTemplateCollection._api_version}/reporttemplates"

base_path

base_path = f"/api/{ReportTemplateCollection._api_version}/reporttemplates"

get_by_id

get_by_id(*, id: str) -> ReportTemplate

Get a single report template by its ID.

Example

template = client.report_templates.get_by_id(id="...")

Parameters:

Name Type Description Default
id str

The ID of the report template to retrieve.

required

Returns:

Type Description
ReportTemplate

The fully populated report template.

Source code in src/albert/collections/report_templates.py
def get_by_id(self, *, id: str) -> ReportTemplate:
    """Get a single report template by its ID.

    !!! example
        ```python
        template = client.report_templates.get_by_id(id="...")
        ```

    Parameters
    ----------
    id : str
        The ID of the report template to retrieve.

    Returns
    -------
    ReportTemplate
        The fully populated report template.
    """
    url = f"{self.base_path}/{id}"
    response = self.session.get(url)
    return ReportTemplate(**response.json())

get_all

get_all(
    *, category: ReportTemplateCategory | None = None
) -> list[ReportTemplate]

List all report templates, optionally filtered by category.

Example

from albert.resources.report_templates import ReportTemplateCategory

templates = client.report_templates.get_all(
    category=ReportTemplateCategory.DATASCIENCE
)

Parameters:

Name Type Description Default
category ReportTemplateCategory | None

Restrict the results to a single template category. If omitted, all categories are returned.

None

Returns:

Type Description
list[ReportTemplate]

The matching report templates.

Source code in src/albert/collections/report_templates.py
def get_all(
    self,
    *,
    category: ReportTemplateCategory | None = None,
) -> list[ReportTemplate]:
    """List all report templates, optionally filtered by category.

    !!! example
        ```python
        from albert.resources.report_templates import ReportTemplateCategory

        templates = client.report_templates.get_all(
            category=ReportTemplateCategory.DATASCIENCE
        )
        ```

    Parameters
    ----------
    category : ReportTemplateCategory | None, optional
        Restrict the results to a single template category. If omitted, all
        categories are returned.

    Returns
    -------
    list[ReportTemplate]
        The matching report templates.
    """
    params = {}
    if category:
        params["category"] = category

    # This microservice has no pagination
    response = self.session.get(self.base_path, params=params)
    return [ReportTemplate(**item) for item in response.json()["Items"]]