Collection
A named group of bookmarks. Collections can be manual (user adds bookmarks explicitly) or smart (bookmarks are included automatically based on a filter rule).
Attributes
| Attribute | Type | Description |
|---|---|---|
| id | string | Unique identifier. |
| name | string | Display name. |
| collection_type | [CollectionType](collectiontype.md?sid=app_models_collection_collectiontype) | Whether the collection is manual or smart. |
| bookmark_ids | List[str] | Ordered list of bookmark IDs in the collection. |
| filter_rule | string | For smart collections, a query string that selects bookmarks. |
| is_pinned | boolean | Whether the collection appears at the top of the sidebar. |
| created_at | datetime | Creation timestamp. |
Constructor
Signature
def Collection(
name: string,
collection_type: [CollectionType](collectiontype.md?sid=app_models_collection_collectiontype) = CollectionType.MANUAL,
bookmark_ids: List[str] = field(default_factory=list),
filter_rule: string = "",
is_pinned: bool = False,
id: str = field(default_factory=lambda: uuid.uuid4().hex[:10]),
created_at: datetime = field(default_factory=datetime.utcnow)
)
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Display name. |
| collection_type | [CollectionType](collectiontype.md?sid=app_models_collection_collectiontype) = CollectionType.MANUAL | Whether the collection is manual or smart. |
| bookmark_ids | List[str] = field(default_factory=list) | Ordered list of bookmark IDs in the collection. |
| filter_rule | string = "" | For smart collections, a query string that selects bookmarks. |
| is_pinned | bool = False | Whether the collection appears at the top of the sidebar. |
| id | str = field(default_factory=lambda: uuid.uuid4().hex[:10]) | Unique identifier. |
| created_at | datetime = field(default_factory=datetime.utcnow) | Creation timestamp. |
Methods
size()
@classmethod
def size() - > integer
Get the number of bookmarks currently in the collection.
Returns
| Type | Description |
|---|---|
integer | The total count of bookmark IDs. |
is_smart()
@classmethod
def is_smart() - > boolean
Check if this collection automatically populates based on a filter rule.
Returns
| Type | Description |
|---|---|
boolean | True if the collection is a smart collection, False otherwise. |
add_bookmark()
@classmethod
def add_bookmark(
bookmark_id: string
) - > boolean
Add a bookmark to a manual collection. Returns False if the bookmark is already present or if the collection is a smart collection.
Parameters
| Name | Type | Description |
|---|---|---|
| bookmark_id | string | The unique identifier of the bookmark to add to the collection. |
Returns
| Type | Description |
|---|---|
boolean | True if the bookmark was successfully added, False otherwise. |
remove_bookmark()
@classmethod
def remove_bookmark(
bookmark_id: string
) - > boolean
Remove a bookmark from the collection. Returns False if the bookmark is not found.
Parameters
| Name | Type | Description |
|---|---|---|
| bookmark_id | string | The unique identifier of the bookmark to remove from the collection. |
Returns
| Type | Description |
|---|---|
boolean | True if the bookmark was successfully removed, False if the bookmark was not found. |
reorder()
@classmethod
def reorder(
bookmark_ids: list
) - > null
Replace the current ordering of bookmarks within the collection with a new list. Raises ValueError if the provided list does not contain exactly the same IDs as the current bookmarks.
Parameters
| Name | Type | Description |
|---|---|---|
| bookmark_ids | list | A list of bookmark IDs representing the desired new order. |
Returns
| Type | Description |
|---|---|
null | This method does not return a value. |
pin()
@classmethod
def pin() - > null
Pin the collection to the top of the sidebar, making it more prominent.
Returns
| Type | Description |
|---|---|
null | This method does not return a value. |
unpin()
@classmethod
def unpin() - > null
Unpin the collection, removing it from the top of the sidebar.
Returns
| Type | Description |
|---|---|
null | This method does not return a value. |
to_dict()
@classmethod
def to_dict() - > dict
Serialize the collection object into a JSON-safe dictionary representation.
Returns
| Type | Description |
|---|---|
dict | A dictionary containing the collection's data, suitable for serialization. |
from_dict()
@classmethod
def from_dict(
data: dict
) - > [Collection](collection.md?sid=app_models_collection_collection)
Construct a new Collection object from a dictionary representation. This is useful for deserializing collections from storage or API responses.
Parameters
| Name | Type | Description |
|---|---|---|
| data | dict | A dictionary containing the collection's data, including 'name', 'type', and optionally 'filter_rule'. |
Returns
| Type | Description |
|---|---|
[Collection](collection.md?sid=app_models_collection_collection) | A new instance of the Collection class populated with data from the dictionary. |