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:
Add-on Development
Command-Line Use
The
Then you can use it in a .py file, like so:
See the Anki module for more.