Skip to content

Albert Client

albert.albert.Albert

Albert(
    *,
    base_url: str | None = None,
    token: str | None = None,
    client_credentials: ClientCredentials | None = None,
    retries: int | None = None,
    session: AlbertSession | None = None,
)

Albert is the main client class for interacting with the Albert API.

Parameters:

Name Type Description Default
base_url str

The base URL of the Albert API (default is "https://app.albertinvent.com").

None
token str

The token for authentication (default is read from environment variable "ALBERT_TOKEN").

None
client_credentials ClientCredentials | None

The client credentials for programmatic authentication. Client credentials can be read from the environment by ClientCredentials.from_env().

None
retries int

The maximum number of retries for failed requests (default is None).

None
session AlbertSession

An optional preconfigured session to use for API requests. If not provided, a default session is created using the other parameters or environment variables. When supplied, base_url, token and client_credentials are ignored.

None

Attributes:

Name Type Description
session AlbertSession

The session for API requests, with a base URL set.

projects ProjectCollection

The project collection instance.

tags TagCollection

The tag collection instance.

inventory InventoryCollection

The inventory collection instance.

companies CompanyCollection

The company collection instance.

Source code in src/albert/albert.py
def __init__(
    self,
    *,
    base_url: str | None = None,
    token: str | None = None,
    client_credentials: ClientCredentials | None = None,
    retries: int | None = None,
    session: AlbertSession | None = None,
):
    self.session = session or AlbertSession(
        base_url=base_url or os.getenv("ALBERT_BASE_URL") or "https://app.albertinvent.com",
        token=token or os.getenv("ALBERT_TOKEN"),
        client_credentials=client_credentials or ClientCredentials.from_env(),
        retries=retries,
    )

session

session = session or AlbertSession(
    base_url=base_url
    or getenv("ALBERT_BASE_URL")
    or "https://app.albertinvent.com",
    token=token or getenv("ALBERT_TOKEN"),
    client_credentials=client_credentials or from_env(),
    retries=retries,
)

projects

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

roles

worksheets

worksheets: WorksheetCollection

tasks

templates

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

albert.utils.credentials.ClientCredentials

Bases: BaseAlbertModel

Client authentication credentials for the Albert API.

Show JSON schema:
{
  "description": "Client authentication credentials for the Albert API.",
  "properties": {
    "id": {
      "title": "Id",
      "type": "string"
    },
    "secret": {
      "format": "password",
      "title": "Secret",
      "type": "string",
      "writeOnly": true
    }
  },
  "required": [
    "id",
    "secret"
  ],
  "title": "ClientCredentials",
  "type": "object"
}

Fields:

id

id: str

secret

secret: SecretStr

from_env

from_env(
    *,
    client_id_env: str = "ALBERT_CLIENT_ID",
    client_secret_env: str = "ALBERT_CLIENT_SECRET",
) -> Union[ClientCredentials, None]

Read ClientCredentials from the environment.

Returns None if the client_id_env and client_secret_env environment variables are not defined.

Parameters:

Name Type Description Default
client_id_env str

Name of the environment variable containing the client ID (defaults to "ALBERT_CLIENT_ID")

'ALBERT_CLIENT_ID'
client_secret_env str

Name of the environment variable containing the client secret (defaults to "ALBERT_CLIENT_SECRET")

'ALBERT_CLIENT_SECRET'

Returns:

Type Description
ClientCredentials | None

The client credentials obtained from the environment, if present.

Source code in src/albert/utils/credentials.py
@classmethod
def from_env(
    cls,
    *,
    client_id_env: str = "ALBERT_CLIENT_ID",
    client_secret_env: str = "ALBERT_CLIENT_SECRET",
) -> Union["ClientCredentials", None]:
    """Read `ClientCredentials` from the environment.

    Returns None if the `client_id_env` and `client_secret_env` environment variables
    are not defined.

    Parameters
    ----------
    client_id_env : str
        Name of the environment variable containing the client ID
        (defaults to "ALBERT_CLIENT_ID")
    client_secret_env : str
        Name of the environment variable containing the client secret
        (defaults to "ALBERT_CLIENT_SECRET")

    Returns
    -------
    ClientCredentials | None
        The client credentials obtained from the environment, if present.
    """
    client_id = os.getenv(client_id_env)
    client_secret = os.getenv(client_secret_env)
    if client_id is not None and client_secret is not None:
        return cls(id=client_id, secret=client_secret)