Pacharapol Withayasakpunt Pacharapol Withayasakpunt
Tue 30 July 2019
Creating and editing Anki's *.apkg and *.anki2 via SQLite

Creating and editing Anki's *.apkg and *.anki2 via SQLite

*.apkg and *.anki2 file structure is very simple, but with some quirks of incompleteness.

*.apkg file structure is a zip of at least two files.

├── example
│   ├── example.anki2
│   ├── media
│   ├── 1  # Media files with the names masked as numbers
│   ├── 2
│   ├── 3
|   └── ...
└── example.apkg

*.anki2 is a SQLite file with foreign key disabled, and the usage of some JSON schemas instead of some tables

Also, *.anki2 is used internally at os.path.join(appdirs.user_data_dir('Anki2'), 'User 1', 'collection.anki2'), so editing the SQLite there will also edit the database.

The media file is a text file of at least a string of {}, which is actually a dictionary of keys -- stringified int; and values -- filenames.

I created a PyPI package is ease the editing of this SQLite (and text file), powered by Peewee ORM.



Creating and editing *.apkg and *.anki2 safely.