Anki SRS apkg reader/writer

Usage no npm install needed!

<script type="module">
  import seangenabeApkg from 'https://cdn.skypack.dev/@seangenabe/apkg';



Anki SRS apkg reader/writer


import { pipeline } from "@improved/node/stream"
import { ZipFile } from "yazl"
import { Apkg } from "@seangenabe/apkg"

async function run() {
  const apkg = new Apkg()

  // modify apkg here

  const files = apkg.save()

  const zip = new ZipFile()
  for (let file of files) {
    zip.addReadStream(Readable.from(file.read(), { objectMode: false }), file.name)
  await pipeline(

class Apkg

Represents an Anki collection file.


#media: ReadableFile[]

Media files

#col: Collection

Collection object.

The conf, models, decks, dconf, and tags properties need not be assigned as they are assigned with objects from the Apkg instance.

#conf: CollectionConfiguration


#models: Model[]

Note types

#decks: Deck[]


#dconf: DeckConfiguration[]

Deck options

#notes: Note[]


#cards: Card[]

#loadFromDb(db: SqlJs.Database)

Loads a collection from an Sql.js database.

#saveToDb(db: SqlJs.Database)

Saves the collection to an Sql.js database.

#save(): IterableIterator

Saves Apkg data to a series of files that can be saved into a .apkg zip file.

A ReadableFile is an object with a property name for the file name and a read(): AsyncIterableIterator<Uint8Array> function that reads from a file (Compatible with a node.js Readable stream).

#load(files: IterableIterator): Promise

Loads Apkg data from a series of files.

Abstraction of file series and streams

An abstraction of series of files and file streams is chosen so as to leave the choice of choosing a zip-handling implementation to the consumer. Likewise, the stream abstraction is to make the package environment-agnostic (node.js / browser).