Tags
albert.collections.tags
AlbertException
AlbertException(message: str)
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
Tag
Bases: BaseResource
Tag is a Pydantic model representing a tag entity.
Attributes:
| Name | Type | Description |
|---|---|---|
tag |
str
|
The name of the tag. |
id |
str | None
|
The Albert ID of the tag. Set when the tag is retrieved from Albert. |
Methods:
| Name | Description |
|---|---|
from_string |
Creates a Tag object from a string. |
id
class-attribute
instance-attribute
id: str | None = Field(
None,
alias=AliasChoices("albertId", "tagId"),
serialization_alias="albertId",
)
tag
class-attribute
instance-attribute
tag: str = Field(
alias=AliasChoices("name", "tagName"),
serialization_alias="name",
)
TagCollection
TagCollection(*, session: AlbertSession)
Bases: BaseCollection
TagCollection is a collection class for managing Tag entities in the Albert platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base URL for tag API requests. |
Methods:
| Name | Description |
|---|---|
get_all |
Lists tag entities with optional filters. |
exists |
Checks if a tag exists by its name. |
create |
Creates a new tag entity. |
get_by_id |
Retrieves a tag by its ID. |
get_by_ids |
Retrieve a list of tags by their IDs. |
get_by_name |
Retrieves a tag by its name. |
delete |
Deletes a tag by its ID. |
rename |
Renames an existing tag entity. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Source code in src/albert/collections/tags.py
create
Creates a new tag entity if the given tag does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
Union[str, Tag]
|
The tag name or Tag object to create. |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The created Tag object or the existing Tag object if it already exists. |
Source code in src/albert/collections/tags.py
delete
delete(*, id: str) -> None
Deletes a tag by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the tag to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/tags.py
exists
Checks if a tag exists by its name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
The name of the tag to check. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the tag exists, False otherwise. |
Source code in src/albert/collections/tags.py
get_all
get_all(
*,
limit: int = 50,
order_by: OrderBy = DESCENDING,
name: str | list[str] | None = None,
exact_match: bool = True,
start_key: str | None = None,
) -> Iterator[Tag]
Get all Tag entities with optional filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The maximum number of tags to return, by default 50. |
50
|
order_by
|
OrderBy
|
The order by which to sort the results, by default OrderBy.DESCENDING. |
DESCENDING
|
name
|
Union[str, None]
|
The name of the tag to filter by, by default None. |
None
|
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
start_key
|
Optional[str]
|
The starting point for the next set of results, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Tag]
|
An iterator of Tag objects. |
Source code in src/albert/collections/tags.py
get_by_id
get_by_ids
Source code in src/albert/collections/tags.py
get_by_name
Retrieves a tag by its name or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tag to retrieve. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
Tag
|
The Tag object if found, None otherwise. |
Source code in src/albert/collections/tags.py
rename
Renames an existing tag entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
The current name of the tag. |
required |
new_name
|
str
|
The new name of the tag. |
required |
Returns:
| Type | Description |
|---|---|
Tag
|
The renamed Tag. |