Hi,
I noticed how genanki (the Python library to write apkg files) has been unmaintained for a few years now, how it uses a legacy format and how many of its issues have not been resolved.
For a few months I’ve been developing genanki2, a new Python library to generate, read and update Anki packages. You can read more about it on the documentation page.
It’s available on PyPI now: pip install genanki2
from genanki2 import BASIC_NOTETYPE, Package, deck, note, package
pkg, collection = package()
collection.add_notes(
[note(BASIC_NOTETYPE, ["Capital of Italy?", "Rome"])],
deck("Geography"),
)
pkg.write_apkg("geography.apkg")
# Then read it back to update it:
pkg = Package.read_apkg("geography.apkg")
- Reads packages: inspect, update and fix
.apkgand.colpkgfiles, including ones exported from Anki. Media files can be extracted to disk. - Updates decks without duplicates: In a build script, genanki2 can generate the ids. Then, read that package back, update and write it again: the ids are read from the file. No more hardcoded ids, no duplicates in a user’s collection.
- Current schema (v18), with media, cloze notetypes, filtered decks and presets. No Anki install needed.
- Checks and repairs: genanki2 refuses to write what Anki would reject or change on import, and warns about likely mistakes.
The API follows the same general shape (notetypes, notes, a deck, a package) as genanki. There’s a migration guide too.
This is the first release (0.1.0), so feedback and bug reports are very welcome. I hope the Anki community finds it useful ![]()
And thanks to all the work the Anki and genanki teams have done over the years
you’re amazing