AnkiTools
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
*.apkgcan 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.
Metadata
Release files for AnkiTools 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| AnkiTools-0.3.7.tar.gz | 44.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| AnkiTools-0.3.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 292.0 kB
Release files / AnkiTools-0.3.7.tar.gz
| Download URL | AnkiTools-0.3.7.tar.gz |
|---|---|
| Size | 44.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
deb16d6bc63aa6d846084b7b2301b3ab9467dc6b9d6f44cfd6f8194ef234d22e
|
|
BLAKE2b-256 checksum How to use checksums |
2d48b01de3fbbff3957d799598e2e882ed757e6978c48d09de739443b35885b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / AnkiTools-0.3.7-py3-none-any.whl
| Download URL | AnkiTools-0.3.7-py3-none-any.whl |
|---|---|
| Size | 248.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f541dce588bfb890087bdc30ab2c0e198a5a116c1c62cdab5ef6a1bfbd4fff6
|
|
BLAKE2b-256 checksum How to use checksums |
53549cc6d54755f8861f83614fe727347187e57eecf16140f0845d646eca5dd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |