anki.tags#

Anki maintains a cache of used tags so it can quickly present a list of tags for autocomplete and in the browser. For efficiency, deletions are not tracked, so unused tags can only be removed from the list with a DB check.

This module manages the tag cache and tags for notes.

Attributes#

Classes#

Module Contents#

anki.tags.TagTreeNode#
anki.tags.CompleteTagRequest#
anki.tags.MARKED_TAG = 'marked'#
class anki.tags.TagManager(col: anki.collection.Collection)#

Bases: anki._legacy.DeprecatedNamesMixin

col#
all() list[str]#
tree() TagTreeNode#
clear_unused_tags() anki.collection.OpChangesWithCount#
set_collapsed(tag: str, collapsed: bool) anki.collection.OpChanges#

Set browser expansion state for tag, registering the tag if missing.

bulk_add(note_ids: collections.abc.Sequence[anki.notes.NoteId], tags: str) anki.collection.OpChangesWithCount#

Add space-separate tags to provided notes, returning changed count.

bulk_remove(note_ids: collections.abc.Sequence[anki.notes.NoteId], tags: str) anki.collection.OpChangesWithCount#
find_and_replace(note_ids: collections.abc.Sequence[int], search: str, replacement: str, regex: bool, match_case: bool) anki.collection.OpChangesWithCount#

Replace instances of ‘search’ with ‘replacement’ in tags. Each tag is matched separately. If the replacement results in an empty string, the tag will be removed.

rename(old: str, new: str) anki.collection.OpChangesWithCount#

Rename provided tag and its children, returning number of changed notes.

remove(space_separated_tags: str) anki.collection.OpChangesWithCount#

Remove the provided tag(s) and their children from notes and the tag list.

reparent(tags: collections.abc.Sequence[str], new_parent: str) anki.collection.OpChangesWithCount#

Change the parent of the provided tags. If new_parent is empty, tags will be reparented to the top-level.

split(tags: str) list[str]#

Parse a string and return a list of tags.

join(tags: list[str]) str#

Join tags into a single string, with leading and trailing spaces.

rem_from_str(deltags: str, tags: str) str#

Delete tags if they exist.

canonify(tag_list: list[str]) list[str]#
in_list(tag: str, tags: list[str]) bool#

True if TAG is in TAGS. Ignore case.

register(tags: collections.abc.Collection[str], usn: int | None = None, clear: bool = False) None#
by_deck(did: anki.decks.DeckId, children: bool = False) list[str]#