Units
albert.collections.units.UnitCollection
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. |
get_by_id |
Retrieves a unit by its ID. |
get_by_ids |
Retrieves a set of units by their IDs |
update |
Updates a unit entity by its ID. |
delete |
Deletes a unit by its ID. |
list |
Lists unit entities with optional filters. |
get_by_name |
Retrieves a unit by its name. |
unit_exists |
Checks if a unit exists by its name. |
Attributes:
Name | Type | Description |
---|---|---|
base_path |
|
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
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
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 |
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
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
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
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. |