Units
albert.collections.units
AlbertPaginator
AlbertPaginator(
*,
path: str,
mode: PaginationMode,
session: AlbertSession,
deserialize: Callable[
[Iterable[dict]], Iterable[ItemType]
],
params: dict[str, str] | None = None,
)
Bases: Iterator[ItemType]
Helper class for pagination through Albert endpoints.
Two pagination modes are possible:
- Offset-based via by the offset query parameter
- Key-based via by the startKey query parameter and 'lastKey' response field
A custom deserialize function is provided when additional logic is required to load
the raw items returned by the search listing, e.g., making additional Albert API calls.
Source code in src/albert/core/pagination.py
AlbertSession
AlbertSession(
*,
base_url: str,
token: str | None = None,
auth_manager: AlbertClientCredentials
| AlbertSSOClient
| None = None,
retries: int | None = None,
)
Bases: Session
A session that has a base URL, which is prefixed to all request URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL to prefix to all relative request paths (e.g., "https://app.albertinvent.com"). |
required |
token
|
str | None
|
A static JWT token for authentication. Ignored if |
None
|
auth_manager
|
AlbertClientCredentials | AlbertSSOClient
|
An authentication manager used to dynamically fetch and refresh tokens.
If provided, it overrides |
None
|
retries
|
int
|
The number of automatic retries on failed requests (default is 3). |
None
|
Methods:
| Name | Description |
|---|---|
request |
|
Source code in src/albert/core/session.py
request
Source code in src/albert/core/session.py
BaseCollection
BaseCollection(*, session: AlbertSession)
BaseCollection is the base class for all collection classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert API Session instance. |
required |
Source code in src/albert/collections/base.py
OrderBy
PaginationMode
Unit
Bases: BaseResource
Unit is a Pydantic model representing a unit entity.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
The Albert ID of the unit. Set when the unit is retrieved from Albert. |
name |
str
|
The name of the unit. |
symbol |
str | None
|
The symbol of the unit. |
synonyms |
List[str] | None
|
The list of synonyms for the unit. |
category |
UnitCategory
|
The category of the unit. |
verified |
bool | None
|
Whether the unit is verified. |
status |
Status | None
|
The status of the unit. Allowed values are |
synonyms
class-attribute
instance-attribute
verified
class-attribute
instance-attribute
verified: bool | None = Field(
default=False, exclude=True, frozen=True
)
UnitCategory
UnitCategory is an enumeration of possible unit categories.
Attributes:
| Name | Type | Description |
|---|---|---|
LENGTH |
str
|
Represents length units. |
VOLUME |
str
|
Represents volume units. |
LIQUID_VOLUME |
str
|
Represents liquid volume units. |
ANGLES |
str
|
Represents angle units. |
TIME |
str
|
Represents time units. |
FREQUENCY |
str
|
Represents frequency units. |
MASS |
str
|
Represents mass units. |
CURRENT |
str
|
Represents electric current units. |
TEMPERATURE |
str
|
Represents temperature units. |
AMOUNT |
str
|
Represents amount of substance units. |
LUMINOSITY |
str
|
Represents luminous intensity units. |
FORCE |
str
|
Represents force units. |
ENERGY |
str
|
Represents energy units. |
POWER |
str
|
Represents power units. |
PRESSURE |
str
|
Represents pressure units. |
ELECTRICITY_AND_MAGNETISM |
str
|
Represents electricity and magnetism units. |
OTHER |
str
|
Represents other units. |
WEIGHT |
str
|
Represents weight units. |
ELECTRICAL_CONDUCTIVITY
class-attribute
instance-attribute
ELECTRICAL_PERMITTIVITY
class-attribute
instance-attribute
ELECTRICITY_AND_MAGNETISM
class-attribute
instance-attribute
UnitCollection
UnitCollection(*, session: AlbertSession)
Bases: BaseCollection
UnitCollection is a collection class for managing Unit entities in the Albert platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Methods:
| Name | Description |
|---|---|
create |
Creates a new unit entity. |
delete |
Deletes a unit by its ID. |
exists |
Checks if a unit exists by its name. |
get_all |
Get all unit entities with optional filters. |
get_by_id |
Retrieves a unit by its ID. |
get_by_ids |
Retrieves a set of units by their IDs |
get_by_name |
Retrieves a unit by its name. |
update |
Updates a unit entity by its ID. |
Source code in src/albert/collections/units.py
create
Creates a new unit entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The unit object to create. |
required |
Returns:
| Type | Description |
|---|---|
Unit
|
The created Unit object. |
Source code in src/albert/collections/units.py
delete
delete(*, id: str) -> None
Deletes a unit by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the unit to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/units.py
exists
Checks if a unit exists by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the unit to check. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the unit exists, False otherwise. |
Source code in src/albert/collections/units.py
get_all
get_all(
*,
limit: int = 100,
name: str | list[str] | None = None,
category: UnitCategory | None = None,
order_by: OrderBy = DESCENDING,
exact_match: bool = False,
start_key: str | None = None,
verified: bool | None = None,
) -> Iterator[Unit]
Get all unit entities with optional filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The maximum number of units to return, by default 50. |
100
|
name
|
Optional[str]
|
The name of the unit to filter by, by default None. |
None
|
category
|
Optional[UnitCategory]
|
The category of the unit to filter by, by default None. |
None
|
order_by
|
OrderBy
|
The order by which to sort the results, by default OrderBy.DESCENDING. |
DESCENDING
|
exact_match
|
bool
|
Whether to match the name exactly, by default False. |
False
|
start_key
|
Optional[str]
|
The starting point for the next set of results, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Unit]
|
An iterator of Unit objects. |
Source code in src/albert/collections/units.py
get_by_id
Retrieves a unit by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the unit to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Unit
|
The Unit object if found. |
Source code in src/albert/collections/units.py
get_by_ids
Retrieves a set of units by their IDs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
The IDs of the units to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[Unit]
|
The Unit objects |
Source code in src/albert/collections/units.py
get_by_name
Retrieves a unit by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the unit to retrieve. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default False. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Unit]
|
The Unit object if found, None otherwise. |
Source code in src/albert/collections/units.py
update
Updates a unit entity by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The updated Unit object. |
required |
Returns:
| Type | Description |
|---|---|
Unit
|
The updated Unit |