Locations
albert.collections.locations.LocationCollection
Bases: BaseCollection
Manage Locations in the Albert platform.
A Location is a physical lab or site (for example, a building, plant, or
campus) where work happens in Albert. Locations are referenced by Tasks and
by Inventory Items to record where an activity is performed or where a
material lives, and each Location can hold one or more Storage Locations
(StorageLocation).
This collection is accessed as client.locations.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for location requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new location. |
get_by_id |
Get a single location by its Albert ID. |
get_all |
Iterate over locations, optionally filtered by name or country. |
update |
Update an existing location. |
exists |
Return the existing location matching the given name, or None. |
get_or_create |
Return the matching location if it exists, otherwise create it. |
delete |
Delete a location by its Albert ID. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/locations.py
get_all
get_all(
*,
ids: list[str] | None = None,
name: str | list[str] | None = None,
country: str | None = None,
exact_match: bool = False,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[Location]
Iterate over Locations, optionally filtered by name or country.
Results are yielded lazily and pagination is handled automatically.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
Restrict results to these Albert location IDs. Maximum of 100. |
None
|
name
|
str or list[str]
|
One or more location names to search for. |
None
|
country
|
str
|
Two-letter country code to filter by (for example, |
None
|
exact_match
|
bool
|
If True, match |
False
|
start_key
|
str
|
Pagination key to resume iteration from a previous page. |
None
|
max_items
|
int
|
Maximum number of locations to return in total. If None, all matching locations are returned. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Location]
|
Locations matching the given filters. |
Source code in src/albert/collections/locations.py
get_by_id
Get a single Location by its Albert ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The Albert ID of the location to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Location
|
The fully populated location. |
Source code in src/albert/collections/locations.py
update
Update an existing Location.
Fetch a location (e.g. via get_by_id), modify the updatable fields on
the returned object, then pass it here. The location is matched by its id.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
The location to update. Its |
required |
Returns:
| Type | Description |
|---|---|
Location
|
The updated location, re-fetched from Albert. |
Notes
The following fields can be updated: address, country,
latitude, longitude, name.
Source code in src/albert/collections/locations.py
exists
Return the existing Location matching the given name, or None.
The match is case-insensitive on name. Useful before creating a
location to avoid duplicates.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
The location to look for. Its |
required |
Returns:
| Type | Description |
|---|---|
Location or None
|
The matching registered location, or None if no match is found. |
Source code in src/albert/collections/locations.py
create
Create a new Location.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
The location to create. |
required |
Returns:
| Type | Description |
|---|---|
Location
|
The newly created location, populated with its assigned |
Source code in src/albert/collections/locations.py
get_or_create
Return the matching Location if it exists, otherwise create it.
Looks for an existing location with the same name (see exists)
and returns it; if none is found, creates the location.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
Location
|
The location to retrieve or create. |
required |
Returns:
| Type | Description |
|---|---|
Location
|
The existing or newly created location. |