anki.decks
==========

.. py:module:: anki.decks


Attributes
----------

.. autoapisummary::

   anki.decks.DeckTreeNode
   anki.decks.DeckNameId
   anki.decks.FilteredDeckConfig
   anki.decks.DeckCollapseScope
   anki.decks.DeckConfigsForUpdate
   anki.decks.UpdateDeckConfigs
   anki.decks.Deck
   anki.decks.DeckDict
   anki.decks.DeckConfigDict
   anki.decks.DeckId
   anki.decks.DeckConfigId
   anki.decks.DEFAULT_DECK_ID
   anki.decks.DEFAULT_DECK_CONF_ID


Classes
-------

.. autoapisummary::

   anki.decks.DecksDictProxy
   anki.decks.DeckManager


Module Contents
---------------

.. py:data:: DeckTreeNode

.. py:data:: DeckNameId

.. py:data:: FilteredDeckConfig

.. py:data:: DeckCollapseScope

.. py:data:: DeckConfigsForUpdate

.. py:data:: UpdateDeckConfigs

.. py:data:: Deck

.. py:data:: DeckDict

.. py:data:: DeckConfigDict

.. py:data:: DeckId

.. py:data:: DeckConfigId

.. py:data:: DEFAULT_DECK_ID

.. py:data:: DEFAULT_DECK_CONF_ID

.. py:class:: DecksDictProxy(col: anki.collection.Collection)

   .. py:method:: keys() -> anki.consts.Any


   .. py:method:: values() -> anki.consts.Any


   .. py:method:: items() -> anki.consts.Any


.. py:class:: DeckManager(col: anki.collection.Collection)

   Bases: :py:obj:`anki._legacy.DeprecatedNamesMixin`


   Expose instance methods/vars as camelCase for legacy callers.


   .. py:attribute:: col


   .. py:attribute:: decks


   .. py:method:: save(deck_or_config: DeckDict | DeckConfigDict | None = None) -> None

      Can be called with either a deck or a deck configuration.



   .. py:method:: add_normal_deck_with_name(name: str) -> anki.collection.OpChangesWithId

      If deck exists, return existing id.



   .. py:method:: add_deck_legacy(deck: DeckDict) -> anki.collection.OpChangesWithId

      Add a deck created with new_deck_legacy(). Must have id of 0.



   .. py:method:: id(name: str, create: bool = True, type: DeckConfigId = DeckConfigId(0)) -> DeckId | None

      Add a deck with NAME. Reuse deck if already exists. Return id as int.



   .. py:method:: remove(dids: collections.abc.Sequence[DeckId]) -> anki.collection.OpChangesWithCount


   .. py:method:: all_names_and_ids(skip_empty_default: bool = False, include_filtered: bool = True) -> collections.abc.Sequence[DeckNameId]

      A sorted sequence of deck names and IDs.



   .. py:method:: id_for_name(name: str) -> DeckId | None


   .. py:method:: get_legacy(did: DeckId) -> DeckDict | None


   .. py:method:: have(id: DeckId) -> bool


   .. py:method:: get_all_legacy() -> list[DeckDict]


   .. py:method:: new_deck() -> Deck

      Return a new normal deck. It must be added with .add_deck() after a name assigned.



   .. py:method:: add_deck(deck: Deck) -> anki.collection.OpChangesWithId


   .. py:method:: new_deck_legacy(filtered: bool) -> DeckDict


   .. py:method:: deck_tree() -> DeckTreeNode


   .. py:method:: find_deck_in_tree(node: DeckTreeNode, deck_id: DeckId) -> DeckTreeNode | None
      :classmethod:



   .. py:method:: all() -> list[DeckDict]

      All decks. Expensive; prefer all_names_and_ids()



   .. py:method:: set_collapsed(deck_id: DeckId, collapsed: bool, scope: DeckCollapseScope) -> anki.collection.OpChanges


   .. py:method:: collapse(did: DeckId) -> None


   .. py:method:: collapse_browser(did: DeckId) -> None


   .. py:method:: count() -> int


   .. py:method:: card_count(dids: DeckId | collections.abc.Iterable[DeckId], include_subdecks: bool) -> anki.consts.Any


   .. py:method:: get(did: DeckId | str, default: bool = True) -> DeckDict | None


   .. py:method:: by_name(name: str) -> DeckDict | None

      Get deck with NAME, ignoring case.



   .. py:method:: update(deck: DeckDict, preserve_usn: bool = True) -> None

      Add or update an existing deck. Used for syncing and merging.



   .. py:method:: update_dict(deck: DeckDict) -> anki.collection.OpChanges


   .. py:method:: rename(deck: DeckDict | DeckId, new_name: str) -> anki.collection.OpChanges

      Rename deck prefix to NAME if not exists. Updates children.



   .. py:method:: reparent(deck_ids: collections.abc.Sequence[DeckId], new_parent: DeckId) -> anki.collection.OpChangesWithCount

      Rename one or more source decks that were dropped on `new_parent`.
      If new_parent is 0, decks will be placed at the top level.



   .. py:method:: get_deck_configs_for_update(deck_id: DeckId) -> DeckConfigsForUpdate


   .. py:method:: update_deck_configs(input: UpdateDeckConfigs) -> anki.collection.OpChanges


   .. py:method:: all_config() -> list[DeckConfigDict]

      A list of all deck config.



   .. py:method:: config_dict_for_deck_id(did: DeckId) -> DeckConfigDict


   .. py:method:: get_config(conf_id: DeckConfigId) -> DeckConfigDict | None


   .. py:method:: update_config(conf: DeckConfigDict, preserve_usn: bool = False) -> None

      preserve_usn is ignored



   .. py:method:: add_config(name: str, clone_from: DeckConfigDict | None = None) -> DeckConfigDict


   .. py:method:: add_config_returning_id(name: str, clone_from: DeckConfigDict | None = None) -> DeckConfigId


   .. py:method:: remove_config(id: DeckConfigId) -> None

      Remove a configuration and update all decks using it.



   .. py:method:: set_config_id_for_deck_dict(deck: DeckDict, id: DeckConfigId) -> None


   .. py:method:: decks_using_config(conf: DeckConfigDict) -> list[DeckId]


   .. py:method:: restore_to_default(conf: DeckConfigDict) -> None


   .. py:method:: name(did: DeckId, default: bool = False) -> str


   .. py:method:: name_if_exists(did: DeckId) -> str | None


   .. py:method:: cids(did: DeckId, children: bool = False) -> list[anki.cards.CardId]


   .. py:method:: for_card_ids(cids: list[anki.cards.CardId]) -> list[DeckId]


   .. py:method:: set_current(deck: DeckId) -> anki.collection.OpChanges


   .. py:method:: get_current_id() -> DeckId

      The currently selected deck ID.



   .. py:method:: current() -> DeckDict


   .. py:method:: active() -> list[DeckId]


   .. py:method:: select(did: DeckId) -> None


   .. py:attribute:: selected


   .. py:method:: path(name: str) -> list[str]
      :staticmethod:



   .. py:method:: basename(name: str) -> str
      :classmethod:



   .. py:method:: immediate_parent_path(name: str) -> list[str]
      :classmethod:



   .. py:method:: immediate_parent(name: str) -> str | None
      :classmethod:



   .. py:method:: key(deck: DeckDict) -> list[str]
      :classmethod:



   .. py:method:: deck_and_child_name_ids(deck_id: DeckId) -> collections.abc.Iterable[tuple[str, DeckId]]

      The deck of did and all its children, as (name, id).



   .. py:method:: children(did: DeckId) -> list[tuple[str, DeckId]]

      All children of did, as (name, id).



   .. py:method:: child_ids(parent_name: str) -> collections.abc.Iterable[DeckId]


   .. py:method:: deck_and_child_ids(deck_id: DeckId) -> list[DeckId]


   .. py:method:: parents(did: DeckId, name_map: dict[str, DeckDict] | None = None) -> list[DeckDict]

      All parents of did.



   .. py:method:: parents_by_name(name: str) -> list[DeckDict]

      All existing parents of name



   .. py:method:: new_filtered(name: str) -> DeckId

      For new code, prefer col.sched.get_or_create_filtered_deck().



   .. py:method:: is_filtered(did: DeckId | str) -> bool


   .. py:method:: flush() -> None


   .. py:method:: rem(did: DeckId, **legacy_args: bool) -> None

      Remove the deck. If cardsToo, delete any cards inside.



   .. py:method:: name_map() -> dict[str, DeckDict]


   .. py:method:: set_deck(cids: list[anki.cards.CardId], did: DeckId) -> None


   .. py:method:: all_ids() -> list[str]


   .. py:method:: all_names(dyn: bool = True, force_default: bool = True) -> list[str]


