anki, located in
pylib/anki
in Anki’s source repo.
The Collection
All operations on a collection file are accessed via aCollection
object. The currently-open Collection is accessible via a global mw.col,
where mw stands for main window. When using the anki module outside
of Anki, you will need to create your own Collection object.
Some basic examples of what you can do follow. Please note that you should put
these in something like testFunction(). You can’t run them
directly in an add-on, as add-ons are initialized during Anki startup, before
any collection or profile has been loaded.
Also please note that accessing the collection directly can lead to the UI
temporarily freezing if the operation doesn’t complete quickly - in practice
you would typically run the code below in a background thread.
Get a due card: