docs-site/addons/hooks-reference.mdx
This page lists all available hooks in Anki. It is generated from pylib/tools/genhooks.py and qt/tools/genhooks_gui.py.
See Hooks & Filters for usage instructions.
anki.hooks)card_odue_was_invalidNo arguments.
No docstring.
schema_will_changeArgs: <code>proceed: bool</code>
Returns: <code>bool</code>
No docstring.
notes_will_be_deletedArgs: <code>col: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/collection#anki.collection.Collection'>anki.collection.Collection</a></code>, <code>ids: Sequence[<a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/notes#anki.notes.NoteId'>anki.notes.NoteId</a>]</code>
No docstring.
note_will_be_addedArgs: <code>col: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/collection#anki.collection.Collection'>anki.collection.Collection</a></code>, <code>note: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/notes#anki.notes.Note'>anki.notes.Note</a></code>, <code>deck_id: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/decks#anki.decks.DeckId'>anki.decks.DeckId</a></code>
Allows modifying a note before it's added to the collection.
This hook may be called both when users use the Add screen, and when add-ons like AnkiConnect add notes. It is not called when importing. If you wish to alter the Add screen, use gui_hooks.add_cards_will_add_note instead.
media_files_did_exportArgs: <code>count: int</code>
Only used by legacy .apkg exporter. Will be deprecated in the future.
legacy_export_progressArgs: <code>progress: str</code>
Temporary hook used in transition to new import/export code.
exporters_list_createdArgs: <code>exporters: list[tuple[str, Any]]</code>
No docstring.
media_file_filterArgs: <code>txt: str</code>
Returns: <code>str</code>
Allows manipulating the file path that media will be read from
field_filterArgs: <code>field_text: str</code>, <code>field_name: str</code>, <code>filter_name: str</code>, <code>ctx: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/template#anki.template.TemplateRenderContext'>anki.template.TemplateRenderContext</a></code>
Returns: <code>str</code>
Allows you to define custom {{filters:..}}
Your add-on can check filter_name to decide whether it should modify field_text or not before returning it.
note_will_flushArgs: <code>note: Note</code>
Allow to change a note before it is added/updated in the database.
card_will_flushArgs: <code>card: Card</code>
Allow to change a card before it is added/updated in the database.
card_did_renderArgs: <code>output: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/template#anki.template.TemplateRenderOutput'>anki.template.TemplateRenderOutput</a></code>, <code>ctx: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/template#anki.template.TemplateRenderContext'>anki.template.TemplateRenderContext</a></code>
Can modify the resulting text after rendering completes.
importing_importersArgs: <code>importers: list[tuple[str, Any]]</code>
Allows updating the list of importers. The resulting list is not saved and should be changed each time the filter is called.
NOTE: Updates to the import/export code are expected in the coming months, and this hook may be replaced with another solution at that time. Tracked on https://github.com/ankitects/anki/issues/1018
deck_added (Obsolete)Args: <code>deck: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/decks#anki.decks.DeckDict'>anki.decks.DeckDict</a></code>
<Warning>Obsolete, do not use.
</Warning>note_type_added (Obsolete)Args: <code>notetype: <a href='https://dev-docs.ankiweb.net/en/latest/autoapi/anki/models#anki.models.NotetypeDict'>anki.models.NotetypeDict</a></code>
<Warning>Obsolete, do not use.
</Warning>sync_stage_did_change (Obsolete)Args: <code>stage: str</code>
<Warning>Obsolete, do not use.
</Warning>sync_progress_did_change (Obsolete)Args: <code>msg: str</code>
<Warning>Obsolete, do not use.
</Warning>