Anki is a powerful open source flashcard application, which helps you quickly and easily memorize facts over the long term utilizing a spaced repetition algorithm. Anki's main form is a desktop application (for Windows, Linux and macOS) which can sync to a web version (AnkiWeb) and mobile versions for Android and iOS.
This is a personal Anki server, which you can sync against instead of AnkiWeb. It was originally developed by David Snopek to support the flashcard functionality on Bibliobird, a web application for language learning.
This version is a fork of jdoe0/ankisyncd. It supports Python 3 and Anki 2.1.
Contents
-
Install the dependencies:
$ pip install -r src/requirements.txt
-
Modify ankisyncd.conf according to your needs
-
Create user:
$ ./ankisyncctl.py adduser <username>
-
Setup a proxy to unchunk the requests.
Webob does not support the header "Transfer-Encoding: chunked" used by Anki and therefore ankisyncd sees chunked requests as empty. To solve this problem setup Nginx (or any other webserver of your choice) and configure it to "unchunk" the requests for ankisyncd.
For example, if you use Nginx on the same machine as ankisyncd, you first have to change the port in
ankisyncd.conf
to something other than27701
. Then configure Nginx to listen on port27701
and forward the unchunked requests to ankisyncd.An example configuration with ankisyncd running on the same machine as Nginx and listening on port
27702
may look like (entire config template click me):server { listen 27701; server_name default; location / { proxy_http_version 1.0; proxy_pass http://127.0.0.1:27702/; } }
-
Run ankisyncd:
$ python -m ankisyncd
Follow these instructions.
1.on add-on window,click Get Add-ons
and fill in the textbox with the code 358444159
2.there,you get add-on custom sync server redirector
,choose it.Then click config
below right
3.apply your server ip address
if this step is taken,the following instructions regarding addon setting 2.1( including 2.1.28 and above) can be skipped.
Create a new directory in the add-ons folder (name it something
like ankisyncd), create a file named __init__.py
containing the code below
and put it in the ankisyncd
directory.
import os
addr = "http://127.0.0.1:27701/" # put your server address here
os.environ["SYNC_ENDPOINT"] = addr + "sync/"
os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/"
Create a new directory in the add-ons folder (name it something
like ankisyncd), create a file named __init__.py
containing the code below
and put it in the ankisyncd
directory.
import anki.sync, anki.hooks, aqt
addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = "%s" + addr
def resetHostNum():
aqt.mw.pm.profile['hostNum'] = None
anki.hooks.addHook("profileLoaded", resetHostNum)
Create a file (name it something like ankisyncd.py) containing the code below
and put it in ~/Anki/addons
.
import anki.sync
addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = addr
anki.sync.SYNC_MEDIA_BASE = addr + "msync/"
Advanced → Custom sync server
Unless you have set up a reverse proxy to handle encrypted connections, use
http
as the protocol. The port will be either the default, 27701, or
whatever you have specified in ankisyncd.conf
(or, if using a reverse proxy,
whatever port you configured to accept the front-end connection).
Use the same base url for both the Sync url
and the Media sync url
, but append /msync
to
the Media sync url
. Do not append /sync
to the Sync url
.
Even though the AnkiDroid interface will request an email address, this is not
required; it will simply be the username you configured with ankisyncctl.py adduser
.
- Prerequites
This project uses GNU Make to simplify the development commands. It also uses Poetry to manage the Python dependencies. Ensure they are installed.
- Create a config for your local environment.
$ cp config/.env.example config/.env.local
See ENVVAR configuration overrides for more information.
- Download Python dependencies.
$ make init
- Run unit tests.
$ make tests
Configuration values can be set via environment variables using ANKISYNCD_
prepended
to the uppercase form of the configuration value. E.g. the environment variable,
ANKISYNCD_AUTH_DB_PATH
will set the configuration value auth_db_path
Environment variables override the values set in the ankisyncd.conf
.
sqlite3 is used by default for user data, authentication and session persistence.
ankisyncd
supports loading classes defined via config that manage most
persistence requirements (the media DB and files are being worked on). All that is
required is to extend one of the existing manager classes and then reference those
classes in the config file. See ankisyncd.conf for example config.