Skip to main content

an Anki *.apkg and collection.anki2 reader and editor

Project description

AnkiTools

Build Status PyPI version shields.io PyPI license PyPI pyversions PyPI status

An Anki *.apkg and collection.anki2 reader and editor to work with in Python. Also included a module on AnkiConnect.

I also created a new sync system called AnkiDirect.

The *.apkg format specification can be viewed from Anki decks collaboration Wiki and AnkiDroid. In my AnkiDirect, I tried to comply with the format specification as much as possible.

Installation

pip install AnkiTools

Features

  • Read and write to Anki database in Application Data.
  • Read and create Anki file without Anki
  • Convert back and forth to Excel.

Examples

import json
from collections import OrderedDict

from AnkiTools import AnkiDirect


if __name__ == '__main__':
    with open(add_info.json) as f:
        data = json.load(f, object_pairs_hook=OrderedDict)

    api = AnkiDirect()
    api.add(data)
    api.conn.commit()

where notes.json is

{
  "data": {
    "note_type A": [
      {
        "data": {
          "header A": "a",
          "header B": "b"
        },
        "decks": {
          "Forward": "Test Deck::Forward",
          "Backward": "Test Deck::Backward"
        }
      }
    ]
  },
  "definitions": {
    "note_type A": {
      "templates": [
        {
          "name": "Forward",
          "data": {
            "qfmt": "{{header A}}",
            "afmt": "{{FrontSide}}\r\n\r\n<hr id=answer>\r\n\r\n{{header B}}"
          }
        },
        {
          "name": "Backward",
          "data": {
            "qfmt": "{{header B}}",
            "afmt": "{{FrontSide}}\r\n\r\n<hr id=answer>\r\n\r\n{{header A}}"
          }
        }
      ],
      "css": ".card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n"
    }
  }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

AnkiTools-0.3.2.tar.gz (12.7 kB view hashes)

Uploaded Source

Built Distribution

AnkiTools-0.3.2-py3-none-any.whl (48.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page