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

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

Featured modules

Anki file conversion

>>> from AnkiTools import anki_convert
>>> anki_convert('Chinese.apkg', out_file='Chinese_anki.xlsx')
>>> anki_convert('my_workbook.xlsx', out_format='.apkg')

The supported formats are .xlsx, .apkg and .anki2.

AnkiDirect API

You can directly edit the Anki app data in user's Application Data path.

from AnkiTools import AnkiDirect
import json

with open('payload.json') as f:
    payload = json.load(f)
with AnkiDirect() as api
    api.add(payload)

Some supported payloads include:

{
  "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"
    }
  }
}

AnkiConnect

>>> from AnkiTools import AnkiConnect
>>> AnkiConnect.is_online()
True
>>> params = {'actions': [{'action': 'deckNames'}, {'action': 'browse', 'params': {'query': 'deck:current'}}]}
>>> AnkiConnect.post('multi', params=params)
{'result': [['Default', 'SpoonFed', 'Chinese Hanzi Freq', 'Chinese Vocab'], None], 'error': None}

The actual addable actions and parameters can be viewed from AnkiConnect.

Plans

  • AnkiDirect two-way sync between Excel file and the Anki app.
  • Specifying metadata (e.g. card distribution, decks) in the Excel file and make it convertible and syncable.
  • Add CRUD to AnkiDirect ("update" and "remove" pending.)

Contributions

  • Testing on other OS's, e.g. Windows XP, Windows 10, Ubuntu Linux. (I tested on Mac.)
  • Manual testing of whether the generated *.apkg can be opened without subsequent errors in the Anki app.
  • Writing test cases and testing parameters. The current ones are viewable at /tests/parameters.json and /tests/files/.
  • Specifying challenging payloads for AnkiDirect.

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.5.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

AnkiTools-0.3.5-py3-none-any.whl (83.8 kB view details)

Uploaded Python 3

File details

Details for the file AnkiTools-0.3.5.tar.gz.

File metadata

  • Download URL: AnkiTools-0.3.5.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for AnkiTools-0.3.5.tar.gz
Algorithm Hash digest
SHA256 3fad29b6e15c5e9083b0b5946761d034059e31a21b274fbcfe03d57348fc856e
MD5 8432614f4a89b0f13213a6ef25d8bf56
BLAKE2b-256 81295fe9054791bc58674ce92eece1d347f448d52e0467e34d1720f75a7ff1c5

See more details on using hashes here.

File details

Details for the file AnkiTools-0.3.5-py3-none-any.whl.

File metadata

File hashes

Hashes for AnkiTools-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f45b182e83a5ed32268d22ea2bdebdaeb9043cbf2a68861c55051becd2482f90
MD5 773d8b87932547f8285a37eb77eeeb9b
BLAKE2b-256 7aa599680815915b3e60bdce56d0243bd7969bdb9fa6f172b7a3053fd01ec66a

See more details on using hashes here.

Supported by

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