Command-Line Use

The anki module can be used separately from Anki's GUI. It is strongly recommended you use it instead of attempting to read or write a .anki2 file directly.

Install it with pip:

$ pip install anki

Then you can use it in a .py file, like so:

from anki.collection import Collection
col = Collection("/path/to/collection.anki2")

See the Anki module for more.