All Projects → FooSoft → Anki Connect

FooSoft / Anki Connect

Licence: other
Anki plugin to expose a remote API for creating flash cards.

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Anki Connect

vocage
A minimalistic spaced-repetion vocabulary trainer (flashcards) for the terminal
Stars: ✭ 68 (-92.03%)
Mutual labels:  anki
Anki Sync Server
Self-hosted Anki sync server
Stars: ✭ 352 (-58.73%)
Mutual labels:  anki
Awesome Anki
A curated list of awesome Anki add-ons, decks and resources
Stars: ✭ 553 (-35.17%)
Mutual labels:  anki
image-occlusion-in-browser
Create image occlusion in browser
Stars: ✭ 20 (-97.66%)
Mutual labels:  anki
Anki Ultimate Geography
Geography flashcard deck for Anki
Stars: ✭ 330 (-61.31%)
Mutual labels:  anki
Anki Editor
Emacs minor mode for making Anki cards with Org
Stars: ✭ 453 (-46.89%)
Mutual labels:  anki
anki-mode
An Emacs major mode for creating anki cards
Stars: ✭ 47 (-94.49%)
Mutual labels:  anki
Review Heatmap
Anki add-on to help you keep track of your review activity
Stars: ✭ 772 (-9.5%)
Mutual labels:  anki
Anki Android
AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
Stars: ✭ 4,425 (+418.76%)
Mutual labels:  anki
Yomichan
Japanese pop-up dictionary extension for Chrome and Firefox.
Stars: ✭ 464 (-45.6%)
Mutual labels:  anki
brain-brew
Automated Anki flashcard creation and extraction to/from Csv
Stars: ✭ 55 (-93.55%)
Mutual labels:  anki
Anki-decks-deeplearning.ai
This repository contains flashcard decks for DeepLearning.ai courses.
Stars: ✭ 43 (-94.96%)
Mutual labels:  anki
Polar Bookshelf
Polar is a personal knowledge repository for PDF and web content supporting incremental reading and document annotation.
Stars: ✭ 4,411 (+417.12%)
Mutual labels:  anki
closet
The Web Framework for Flashcards
Stars: ✭ 45 (-94.72%)
Mutual labels:  anki
Odh
A chrome extension to show online dictionary content.
Stars: ✭ 695 (-18.52%)
Mutual labels:  anki
Fabricius
Fabricius is an Anki plugin that bidirectionally syncs between Roam and Anki.
Stars: ✭ 54 (-93.67%)
Mutual labels:  anki
Obsidian to anki
Script to add flashcards from text/markdown files to Anki
Stars: ✭ 382 (-55.22%)
Mutual labels:  anki
Anki Backup
My anki cards' backups. Java、大数据、数据结构八股文。
Stars: ✭ 26 (-96.95%)
Mutual labels:  anki
Genanki
A Python 3 library for generating Anki decks
Stars: ✭ 711 (-16.65%)
Mutual labels:  anki
Vector Python Sdk
Anki Vector Python SDK
Stars: ✭ 462 (-45.84%)
Mutual labels:  anki

AnkiConnect

AnkiConnect enables external applications such as Yomichan to communicate with Anki over a simple HTTP API. Its capabilities include executing queries against the user's card deck, automatically creating new cards, and more. AnkiConnect is compatible with the latest stable (2.1.x) releases of Anki; older versions (2.0.x and below) are no longer supported.

Installation

The installation process is similar to other Anki plugins and can be accomplished in three steps:

  1. Open the Install Add-on dialog by selecting Tools | Add-ons | Get Add-ons... in Anki.
  2. Input 2055492159 into the text box labeled Code and press the OK button to proceed.
  3. Restart Anki when prompted to do so in order to complete the installation of AnkiConnect.

Anki must be kept running in the background in order for other applications to be able to use AnkiConnect. You can verify that AnkiConnect is running at any time by accessing localhost:8765 in your browser. If the server is running, you will see the message AnkiConnect displayed in your browser window.

Notes for Windows Users

Windows users may see a firewall nag dialog box appear on Anki startup. This occurs because AnkiConnect runs a local HTTP server in order to enable other applications to connect to it. The host application, Anki, must be unblocked for this plugin to function correctly.

Notes for Mac OS X Users

Starting with Mac OS X Mavericks, a feature named App Nap has been introduced to the operating system. This feature causes certain applications which are open (but not visible) to be placed in a suspended state. As this behavior causes AnkiConnect to stop working while you have another window in the foreground, App Nap should be disabled for Anki:

  1. Start the Terminal application.
  2. Execute the following commands in the terminal window:
    • defaults write net.ankiweb.dtop NSAppSleepDisabled -bool true
    • defaults write net.ichi2.anki NSAppSleepDisabled -bool true
    • defaults write org.qt-project.Qt.QtWebEngineCore NSAppSleepDisabled -bool true
  3. Restart Anki.

Application Interface for Developers

AnkiConnect exposes internal Anki features to external applications via an easy to use API. After being installed, this plugin will start an HTTP sever on port 8765 whenever Anki is launched. Other applications (including browser extensions) can then communicate with it via HTTP requests.

By default, AnkiConnect will only bind the HTTP server to the 127.0.0.1 IP address, so that you will only be able to access it from the same host on which it is running. If you need to access it over a network, you can set the environment variable ANKICONNECT_BIND_ADDRESS to change the binding address. For example, you can set it to 0.0.0.0 in order to bind it to all network interfaces on your host.

Sample Invocation

Every request consists of a JSON-encoded object containing an action, a version, contextual params, and a key value used for authentication (which is optional and can be omitted by default). AnkiConnect will respond with an object containing two fields: result and error. The result field contains the return value of the executed API, and the error field is a description of any exception thrown during API execution (the value null is used if execution completed successfully).

Sample successful response:

{"result": ["Default", "Filtered Deck 1"], "error": null}

Samples of failed responses:

{"result": null, "error": "unsupported action"}
{"result": null, "error": "guiBrowse() got an unexpected keyword argument 'foobar'"}

For compatibility with clients designed to work with older versions of AnkiConnect, failing to provide a version field in the request will make the version default to 4. Furthermore, when the provided version is level 4 or below, the API response will only contain the value of the result; no error field is available for error handling.

You can use whatever language or tool you like to issue request to AnkiConnect, but a couple of simple examples are included below as reference.

Curl

curl localhost:8765 -X POST -d "{\"action\": \"deckNames\", \"version\": 6}"

Python

import json
import urllib.request

def request(action, **params):
    return {'action': action, 'params': params, 'version': 6}

def invoke(action, **params):
    requestJson = json.dumps(request(action, **params)).encode('utf-8')
    response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson)))
    if len(response) != 2:
        raise Exception('response has an unexpected number of fields')
    if 'error' not in response:
        raise Exception('response is missing required error field')
    if 'result' not in response:
        raise Exception('response is missing required result field')
    if response['error'] is not None:
        raise Exception(response['error'])
    return response['result']

invoke('createDeck', deck='test1')
result = invoke('deckNames')
print('got list of decks: {}'.format(result))

JavaScript

function invoke(action, version, params={}) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.addEventListener('error', () => reject('failed to issue request'));
        xhr.addEventListener('load', () => {
            try {
                const response = JSON.parse(xhr.responseText);
                if (Object.getOwnPropertyNames(response).length != 2) {
                    throw 'response has an unexpected number of fields';
                }
                if (!response.hasOwnProperty('error')) {
                    throw 'response is missing required error field';
                }
                if (!response.hasOwnProperty('result')) {
                    throw 'response is missing required result field';
                }
                if (response.error) {
                    throw response.error;
                }
                resolve(response.result);
            } catch (e) {
                reject(e);
            }
        });

        xhr.open('POST', 'http://127.0.0.1:8765');
        xhr.send(JSON.stringify({action, version, params}));
    });
}

await invoke('createDeck', {deck: 'test1'});
const result = await invoke('deckNames', 6);
console.log(`got list of decks: ${result}`);

Supported Actions

Documentation for currently supported actions is split up by category and is referenced below. Note that deprecated APIs will continue to function despite not being listed on this page as long as your request is labeled with a version number corresponding to when the API was available for use.

Hey, could you add a new action to support $FEATURE?

The primary goal for AnkiConnect was to support real-time flash card creation from the Yomichan browser extension. The current API provides all the required actions to make this happen. I recognise that the role of AnkiConnect has evolved from this original vision, and I am happy to review new feature requests.

With that said, this project operates on a self-serve model. If you would like a new feature, create a PR. I'll review it and if it looks good, it will be merged in. Requests to add new features without accompanying PRs will not be serviced. Make sure that your PRs meet the following criteria:

  • Attempt to match style of the surrounding code.
  • Have accompanying documentation with examples.
  • Have accompanying tests that verify operation.
  • Implement features useful in other applications.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].