Skip to main content

GitHub Release PyPI Version Python Versions CI AGPLv3+ Sponsor

kanjidraw - handwritten kanji recognition

kanjidraw is a simple Python library + GUI for matching (the strokes of a) handwritten kanji against its database.

You can use the GUI to draw and subsequently select a kanji from the list of probable matches, which will then be copied to the clipboard.

The database is based on KanjiVG and the algorithms are based on the Kanji draw Android app.

Demo

Jiten Japanese Dictionary uses kanjidraw with a JavaScript frontend.

Requirements

  • Python >= 3.5 (w/ Tk support for the GUI).

Debian/Ubuntu

$ apt install python3-tk

Installing

Using pip

$ pip install kanjidraw

NB: depending on your system you may need to use e.g. pip3 --user instead of just pip.

From git

NB: this installs the latest development version, not the latest release.

$ git clone https://github.com/obfusk/kanjidraw.git
$ cd kanjidraw
$ pip install -e .

NB: you may need to add e.g. ~/.local/bin to your $PATH in order to run kanjidraw.

To update to the latest development version:

$ cd kanjidraw
$ git pull --rebase

Examples

Kanji Input on Linux

kanjidraw-paste

Opens kanjidraw to select one (--oneshot) or multiple (--multiple) kanji, and afterwards pastes the selected kanji in the active window. Requires xclip and xdotool.

#!/bin/bash
set -e
pid="$( xdotool getactivewindow getwindowpid )"
pids() { xdotool search --classname "$1" getwindowpid %@; }
if pids urxvt | grep -q "^$pid$"; then
  key=ctrl+alt+v
elif pids terminal | grep -q "^$pid$"; then
  key=ctrl+shift+v
else
  key=ctrl+v
fi
kanjidraw -s "$@" | tr -d '\n' | xclip -i -selection clipboard
xdotool key --delay 250 "$key"

i3 config

Keybindings for i3. Creating custom keybindings for kanjidraw-paste --oneshot and/or kanjidraw-paste --multiple should work similarly with other window managers and desktop environments.

for_window [title="Kanji Draw"] floating enable
bindsym $mod+Control+k exec --no-startup-id kanjidraw-paste --oneshot
bindsym $mod+Control+m exec --no-startup-id kanjidraw-paste --multiple

Miscellaneous

GUI Options

$ kanjidraw --help
usage: kanjidraw [-h] [-s] [-o | -m] [-d] [--version]

optional arguments:
  -h, --help      show this help message and exit
  -s, --stdout    print kanji to stdout instead of copying to clipboard
  -o, --oneshot   quit after one kanji
  -m, --multiple  queue kanji and copy/print after pressing 'c' or quitting
  -d, --dark      use dark theme
  --version       show program's version number and exit

Additional keybindings: q to quit, <esc> to go back.

Enabling Dark Mode

$ export KANJIDRAW_DARK=1

Disabling the Grid

$ export KANJIDRAW_NOGRID=1

License

Code

© Felix C. Stegerman

AGPLv3+

KanjiVG (stroke data)

© Ulrich Apel

CC-BY-SA

Metadata

Release files for kanjidraw 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kanjidraw 0.2.3
File Size Uploaded
kanjidraw-0.2.3.tar.gz 519.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kanjidraw 0.2.3
File Interpreter ABI Platform
kanjidraw-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / kanjidraw-0.2.3.tar.gz

Download URL kanjidraw-0.2.3.tar.gz
Size 519.3 kB
Tags Source
SHA-256 checksum
How to use checksums
170067b144455c90eaad52432de8f103ae3b63f56025db0d7b842aee06859d85
BLAKE2b-256 checksum
How to use checksums
6e036119b7c7398c56161b39814b5b5a9617f730a2550c7661f8809dda492015
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release files / kanjidraw-0.2.3-py3-none-any.whl

Download URL kanjidraw-0.2.3-py3-none-any.whl
Size 542.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56841978197a7ba71c553fdc3cefda79a53cff339167974cc0e590f299a63100
BLAKE2b-256 checksum
How to use checksums
82a81002fed73f4b3e6ec20b827a9e4eb3daf94d9a564461d905bcd878030281
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page