Units
albert.collections.units
AlbertSession
AlbertSession(
*,
base_url: str,
token: str | None = None,
client_credentials: ClientCredentials | 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 requests. (e.g., "https://sandbox.albertinvent.com") |
required |
retries
|
int
|
The number of retries for failed requests. Defaults to 3. |
None
|
client_credentials
|
ClientCredentials | None
|
The client credentials for programmatic authentication. Optional if token is provided. |
None
|
token
|
str | None
|
The JWT token for authentication. Optional if client credentials are provided. |
None
|
Methods:
Name | Description |
---|---|
request |
|
Source code in src/albert/session.py
request
Source code in src/albert/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
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. |
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. |
list |
Lists unit entities with optional filters. |
unit_exists |
Checks if a unit exists 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
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
list
list(
*,
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]
Lists 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
unit_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
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 |