Tags
albert.collections.tags.TagCollection
Bases: BaseCollection
Manage Tags in the Albert platform.
A Tag is a freeform text label used to categorize and connect entities across the platform, such as inventory items, companies, and tasks. Tags are shared: the same tag can be applied to many entities, which makes them useful for grouping and filtering related records.
Because tags are identified by their text, the common pattern is to find an
existing tag or create it on demand via get_or_create. Tags are
referenced by their Tag ID (format TAG..., e.g. "TAG1").
This collection is accessed as client.tags.
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 tag requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new tag. |
get_or_create |
Return the existing tag matching the name, or create it. |
get_by_id |
Get a single tag by its ID. |
get_by_ids |
Get many tags by their IDs. |
get_by_name |
Get a tag by name, or None if not found. |
get_all |
Iterate over tags with optional filters. |
rename |
Rename an existing tag. |
delete |
Delete a tag by its ID. |
exists |
Check whether a tag with the given name exists. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/tags.py
exists
Check whether a tag with the given name exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
The tag name to check. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if a matching tag exists, False otherwise. |
Source code in src/albert/collections/tags.py
create
Create a new tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str or Tag
|
The tag to create, given either as a plain name or a |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The newly created tag, including its assigned Tag ID. |
Source code in src/albert/collections/tags.py
get_or_create
Return the existing tag matching the given name, or create it.
Looks for an existing tag with the same name (exact match). If one is found it is returned unchanged; otherwise a new tag is created. This is the recommended way to reference a tag, since tags are shared by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str or Tag
|
The tag to find or create, given either as a plain name or a
|
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The existing or newly created tag. |
Source code in src/albert/collections/tags.py
get_by_id
Get a single tag by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TagId
|
The Tag ID to retrieve (format |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The fully populated tag. |
Source code in src/albert/collections/tags.py
get_by_ids
Get many tags by their IDs.
IDs are fetched in batches, so arbitrarily long lists are supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[TagId]
|
The Tag IDs to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
list[Tag]
|
The matching tags. Tags not found are omitted. |
Source code in src/albert/collections/tags.py
get_by_name
Get a tag by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The tag name to retrieve. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
Tag or None
|
The matching tag, or None if no tag with that name exists. |
Source code in src/albert/collections/tags.py
delete
delete(*, id: TagId) -> None
Delete a tag by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TagId
|
The Tag ID to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/tags.py
rename
Rename an existing tag.
The tag is looked up by its current name and updated in place, so every entity carrying the tag reflects the new name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The current name of the tag. |
required |
new_name
|
str
|
The new name to give the tag. |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The renamed tag. |
Raises:
| Type | Description |
|---|---|
AlbertException
|
If no tag with |
Source code in src/albert/collections/tags.py
get_all
get_all(
*,
order_by: OrderBy = DESCENDING,
name: str | list[str] | None = None,
exact_match: bool = True,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[Tag]
Iterate over tags, with optional filters.
Results are fetched page by page as you iterate, so this scales to large result sets without loading everything at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order_by
|
OrderBy
|
Sort direction for results. Defaults to |
DESCENDING
|
name
|
str or list[str]
|
Filter tags by one or more names. |
None
|
exact_match
|
bool
|
Whether to match the name(s) exactly. Defaults to True. |
True
|
start_key
|
str
|
Pagination key to resume iteration from a previous position. |
None
|
max_items
|
int
|
Maximum number of tags to return in total. If None, iterates over all matching tags. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Tag]
|
An iterator over the matching tags. |