Skip to main content

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

AttributeTypeDescription
idstringUnique identifier.
namestringDisplay name.
collection_type[CollectionType](collectiontype.md?sid=app_models_collection_collectiontype)Whether the collection is manual or smart.
bookmark_idsList[str]Ordered list of bookmark IDs in the collection.
filter_rulestringFor smart collections, a query string that selects bookmarks.
is_pinnedbooleanWhether the collection appears at the top of the sidebar.
created_atdatetimeCreation 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

NameTypeDescription
namestringDisplay name.
collection_type[CollectionType](collectiontype.md?sid=app_models_collection_collectiontype) = CollectionType.MANUALWhether the collection is manual or smart.
bookmark_idsList[str] = field(default_factory=list)Ordered list of bookmark IDs in the collection.
filter_rulestring = ""For smart collections, a query string that selects bookmarks.
is_pinnedbool = FalseWhether the collection appears at the top of the sidebar.
idstr = field(default_factory=lambda: uuid.uuid4().hex[:10])Unique identifier.
created_atdatetime = field(default_factory=datetime.utcnow)Creation timestamp.

Methods


size()

@classmethod
def size() - > integer

Get the number of bookmarks currently in the collection.

Returns

TypeDescription
integerThe total count of bookmark IDs.

is_smart()

@classmethod
def is_smart() - > boolean

Check if this collection automatically populates based on a filter rule.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
bookmark_idstringThe unique identifier of the bookmark to add to the collection.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
bookmark_idstringThe unique identifier of the bookmark to remove from the collection.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
bookmark_idslistA list of bookmark IDs representing the desired new order.

Returns

TypeDescription
nullThis 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

TypeDescription
nullThis method does not return a value.

unpin()

@classmethod
def unpin() - > null

Unpin the collection, removing it from the top of the sidebar.

Returns

TypeDescription
nullThis method does not return a value.

to_dict()

@classmethod
def to_dict() - > dict

Serialize the collection object into a JSON-safe dictionary representation.

Returns

TypeDescription
dictA 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

NameTypeDescription
datadictA dictionary containing the collection's data, including 'name', 'type', and optionally 'filter_rule'.

Returns

TypeDescription
[Collection](collection.md?sid=app_models_collection_collection)A new instance of the Collection class populated with data from the dictionary.