Skip to content

Albert Client

albert.Albert

Albert(
    *,
    base_url: str | None = None,
    token: str | None = None,
    auth_manager: AlbertClientCredentials
    | AlbertSSOClient
    | None = None,
    retries: int | None = None,
    session: AlbertSession | None = None,
)

Main client for interacting with the Albert API.

This class manages authentication and access to API resource collections. It supports token-based, SSO, and client credentials authentication via a unified interface.

Parameters:

Name Type Description Default
base_url str

The base URL of the Albert API. If not provided, the URL from auth_manager is used when available, otherwise the ALBERT_BASE_URL environment variable or "https://app.albertinvent.com".

None
token str

A static token for authentication. If provided, it overrides any auth_manager. Defaults to the "ALBERT_TOKEN" environment variable.

None
auth_manager AlbertClientCredentials | AlbertSSOClient

An authentication manager for OAuth2-based authentication flows. Ignored if token is provided.

None
retries int

Maximum number of retries for failed HTTP requests.

None
session AlbertSession

A fully configured session instance. If provided, base_url, token, and auth_manager are all ignored.

None

Attributes:

Name Type Description
session AlbertSession

The internal session used for authenticated requests.

projects ProjectCollection

Access to project-related API methods.

tags TagCollection

Access to tag-related API methods.

inventory InventoryCollection

Access to inventory-related API methods.

companies CompanyCollection

Access to company-related API methods.

Helpers
  • from_token — Create a client using a static token.
  • from_sso — Create a client using interactive browser-based SSO login.
  • from_client_credentials — Create a client using OAuth2 client credentials.

Methods:

Name Description
from_token

Create an Albert client using a static token for authentication.

from_sso

Create an Albert client using interactive OAuth2 SSO login.

from_client_credentials

Create an Albert client using client credentials authentication.

Source code in src/albert/client.py
def __init__(
    self,
    *,
    base_url: str | None = None,
    token: str | None = None,
    auth_manager: AlbertClientCredentials | AlbertSSOClient | None = None,
    retries: int | None = None,
    session: AlbertSession | None = None,
):
    if auth_manager and base_url and base_url != auth_manager.base_url:
        raise ValueError("`base_url` must match the URL used by the auth manager.")

    resolved_base_url = (
        base_url
        or (auth_manager.base_url if auth_manager else None)
        or default_albert_base_url()
    )

    self.session = session or AlbertSession(
        base_url=resolved_base_url,
        token=token or os.getenv("ALBERT_TOKEN"),
        auth_manager=auth_manager,
        retries=retries,
    )

session

session = session or AlbertSession(
    base_url=resolved_base_url,
    token=token or getenv("ALBERT_TOKEN"),
    auth_manager=auth_manager,
    retries=retries,
)

projects

activities

activities: ActivityCollection

attachments

attachments: AttachmentCollection

tags

inventory

companies

companies: CompanyCollection

lots

units

cas_numbers

cas_numbers: CasCollection

data_columns

data_columns: DataColumnCollection

data_templates

data_templates: DataTemplateCollection

un_numbers

un_numbers: UnNumberCollection

users

locations

locations: LocationCollection

lists

notebooks

notebooks: NotebookCollection

notes

custom_fields

custom_fields: CustomFieldCollection

reports

report_templates

report_templates: ReportTemplateCollection

roles

worksheets

worksheets: WorksheetCollection

tasks

custom_templates

custom_templates: CustomTemplatesCollection

parameter_groups

parameter_groups: ParameterGroupCollection

parameters

parameters: ParameterCollection

property_data

property_data: PropertyDataCollection

product_design

product_design: ProductDesignCollection

storage_locations

storage_locations: StorageLocationsCollection

pricings

files

workflows

workflows: WorkflowCollection

btdatasets

btdatasets: BTDatasetCollection

btmodelsessions

btmodelsessions: BTModelSessionCollection

btmodels

btinsights

btinsights: BTInsightCollection

substances

substances: SubstanceCollection

batch_data

batch_data: BatchDataCollection

from_token

from_token(*, base_url: str | None, token: str) -> Albert

Create an Albert client using a static token for authentication.

Source code in src/albert/client.py
@classmethod
def from_token(cls, *, base_url: str | None, token: str) -> Albert:
    """Create an Albert client using a static token for authentication."""
    return cls(base_url=base_url, token=token)

from_sso

from_sso(
    *,
    base_url: str | None,
    email: str,
    port: int = 5000,
    tenant_id: str | None = None,
    retries: int | None = None,
) -> Albert

Create an Albert client using interactive OAuth2 SSO login.

Source code in src/albert/client.py
@classmethod
def from_sso(
    cls,
    *,
    base_url: str | None,
    email: str,
    port: int = 5000,
    tenant_id: str | None = None,
    retries: int | None = None,
) -> Albert:
    """Create an Albert client using interactive OAuth2 SSO login."""
    resolved_base_url = base_url or default_albert_base_url()
    oauth = AlbertSSOClient(base_url=resolved_base_url, email=email)
    oauth.authenticate(minimum_port=port, tenant_id=tenant_id)
    return cls(auth_manager=oauth, retries=retries)

from_client_credentials

from_client_credentials(
    *,
    base_url: str | None,
    client_id: str,
    client_secret: str,
    retries: int | None = None,
) -> Albert

Create an Albert client using client credentials authentication.

Source code in src/albert/client.py
@classmethod
def from_client_credentials(
    cls,
    *,
    base_url: str | None,
    client_id: str,
    client_secret: str,
    retries: int | None = None,
) -> Albert:
    """Create an Albert client using client credentials authentication."""
    resolved_base_url = base_url or default_albert_base_url()
    creds = AlbertClientCredentials(
        id=client_id,
        secret=SecretStr(client_secret),
        base_url=resolved_base_url,
    )
    return cls(auth_manager=creds, retries=retries)