Skip to main content

kanjiconv

Python License PyPI Downloads

EN | JA

kanjiconv

Kanji Converter to Hiragana, Katakana, Roman alphabet.
You can get the reading and pronunciation of Japanese sentences based on sudachidict.
Sudachidict is a regularly updated dictionary, so it can relatively handle new proper nouns and other terms.

Environment

3.10 <= Python <= 3.15

Security notice: eMudhra CA certificate compromise

The private keys of eight eMudhra (emSign) intermediate CA certificates have been compromised (advisory). Older Python installations trust these certificates through their bundled pip/certifi. This affects HTTPS downloads such as pip install and python -m unidic download.

  • Upgrade Python to 3.15.1, 3.14.9, 3.13.17, or a later release in the same series.
  • In existing environments (including virtualenvs), update pip and certifi:
    pip install -U "pip>=26.2.2" "certifi>=2026.10.19"
    
  • Python 3.10 to 3.12 have no patched release. Updating pip and certifi as shown above is required.

When imported, kanjiconv emits an InsecurePythonWarning if the running Python is older than the patched release of its series. To silence it after updating pip/certifi, set KANJICONV_SUPPRESS_PYTHON_WARNING=1 or filter the warning:

import warnings
from kanjiconv import InsecurePythonWarning
warnings.filterwarnings("ignore", category=InsecurePythonWarning)

Install

Install kanjiconv

pip install kanjiconv

fugashi/unidic are not installed by default. If you want to use the UniDic dictionary with the use_unidic option, install the optional extra and download the dictionary:

pip install "kanjiconv[unidic]"
python -m unidic download

Passing use_unidic=True (or --use-unidic on the CLI) without this extra installed raises ImportError with the install instructions above.

How to use

CLI usage

After installing kanjiconv, you can use the kanjiconv command from your terminal.

kanjiconv "幽☆遊☆白書は、最高の漫画デス。"

Text can also be piped to the command when no positional text is provided:

echo "幽☆遊☆白書は、最高の漫画デス。" | kanjiconv --mode hiragana --separator ""
# ゆうゆうはくしょは、さいこうのまんがです。

By default, the CLI converts text to roman alphabet and inserts a single space between token readings.

yuuyuuhakusho ha ,  saikou no manga desu .

Use -m/--mode to choose the output format:

# Convert to hiragana
kanjiconv "幽☆遊☆白書は、最高の漫画デス。" --mode hiragana

# Convert to katakana
kanjiconv "幽☆遊☆白書は、最高の漫画デス。" --mode katakana

# Convert to roman alphabet (which is already the default)
kanjiconv "幽☆遊☆白書は、最高の漫画デス。" --mode roman

Use -s/--separator to change the separator inserted between token readings:

kanjiconv "幽☆遊☆白書は、最高の漫画デス。" --mode hiragana --separator "/"
# ゆうゆうはくしょ/は/、/さいこう/の/まんが/です/。

kanjiconv "幽☆遊☆白書は、最高の漫画デス。" --mode hiragana --separator ""
# ゆうゆうはくしょは、さいこうのまんがです。

Additional options:

# Use UniDic as a fallback for readings when available
kanjiconv "東京に行く" --mode hiragana --use-unidic

# Disable the custom reading fallback
kanjiconv "激を飛ばす" --mode hiragana --no-custom-readings

CLI flags/options

Option Description
-m/--mode {roman,hiragana,katakana} Conversion mode. Defaults to roman.
-s/--separator SEPARATOR Separator inserted between token readings. Defaults to a single space.
--use-unidic Use UniDic as a fallback for readings when available (requires the kanjiconv[unidic] extra).
--no-custom-readings Disable custom reading fallback.
--split-mode {A,B,C} Sudachi split granularity. Defaults to C (longest units).
--version Show the installed version.
-h/--help Show help.

Import & Create Instance

from kanjiconv import KanjiConv

# Basic usage
kanji_conv = KanjiConv(separator="/")

# Using UniDic for improved kanji reading accuracy
# (requires `pip install "kanjiconv[unidic]"` and `python -m unidic download`,
# otherwise raises ImportError)
kanji_conv = KanjiConv(separator="/", use_unidic=True)

# Using custom dictionary for kanji readings not covered by SudachiDict or UniDic
kanji_conv = KanjiConv(separator="/", use_custom_readings=True)

Get Reading

# convert to hiragana
text = "幽☆遊☆白書は、最高の漫画デス。"
print(kanji_conv.to_hiragana(text))
ゆうゆうはくしょ/は/、/さいこう/の/まんが/です/。

# convert to katakana
text = "幽☆遊☆白書は、最高の漫画デス。"
print(kanji_conv.to_katakana(text))
ユウユウハクショ/ハ/、/サイコウ/ノ/マンガ/デス/。

# convert to Roman alphabet
text = "幽☆遊☆白書は、最高の漫画デス。"
print(kanji_conv.to_roman(text))
yuuyuuhakusho/ha/, /saikou/no/manga/desu/. 

# You can change separator to another character or None
kanji_conv = KanjiConv(separator="_")
print(kanji_conv.to_hiragana(text))
ゆうゆうはくしょ_は_、_さいこう_の_まんが_です_。

kanji_conv = KanjiConv(separator="")
print(kanji_conv.to_hiragana(text))
ゆうゆうはくしょは、さいこうのまんがです。

Using Custom Kanji Reading Dictionary

KanjiConv supports a custom dictionary for handling special kanji readings that are not properly recognized by SudachiDict or UniDic. This is particularly useful for:

  1. Special expressions with unique readings
  2. Technical terms or proper nouns
  3. Ambiguous kanji with multiple readings based on context

The custom dictionary is automatically loaded from the package if available, but you can also define your own:

from kanjiconv import KanjiConv

# Create instance with custom readings enabled (enabled by default)
kanji_conv = KanjiConv(separator="/", use_custom_readings=True)

# You can also define your own custom readings
kanji_conv.custom_readings = {
    "single": {
        "激": ["げき"],
        "飛": ["と", "ひ"]
    },
    "compound": {
        "激を飛ばす": "げきをとばす",
        "飛ばす": "とばす"
    }
}

# Now the special expression will be properly converted
print(kanji_conv.to_hiragana("激を飛ばす"))
# Output: げき/を/とばす

Custom Dictionary Structure

The custom dictionary uses the following format:

  • single: A dictionary mapping individual kanji to their reading(s)
    • Each kanji can have multiple readings as a list
    • The first reading in the list is used as default
  • compound: A dictionary mapping multi-character expressions to their reading
    • These are processed before tokenization and given priority

(Optional) Installing sudachidict other than the default

The default dictionary is sudachidict_full. If you want to use a lighter dictionary, you can install either sudachidict_small or sudachidict_core.

  • If you need detailed readings, we recommend using sudachidict_full. The default is set to sudachidict_full.
  • If you prefer lighter operation, sudachidict_small is recommended.
  • sudachidict_core offers a balanced option between speed and accuracy.
pip install sudachidict_small
pip install sudachidict_core
  • If using sudachidict_small or sudachidict_core, specify it like this:
kanji_conv = KanjiConv(sudachi_dict_type="small", separator="/")
kanji_conv = KanjiConv(sudachi_dict_type="core", separator="/")

Update Dict

kanjiconv reading function is based on SudachiDict, and you need to update SudachiDict regularly via pip.

pip install -U sudachidict_full
pip install -U sudachidict_small
pip install -U sudachidict_core

Local MCP Server

If you want to use kanjiconv as a local MCP Server, see kanjicon-mcp

License

This project is licensed under the Apache License 2.0.

Open Source Software Used

This library uses SudachiPy and its dictionary SudachiDict for morphological analysis. These are also distributed under the Apache License 2.0.

For detailed license information, please refer to the LICENSE files of each project:

Metadata

Release files for kanjiconv 0.4.0

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

Source distribution (sdist)

Source distribution for kanjiconv 0.4.0
File Size Uploaded Provenance Actions
kanjiconv-0.4.0.tar.gz 124.0 kB Without provenance Details for kanjiconv-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 144.4 kB

Release files / kanjiconv-0.4.0.tar.gz

Download URL kanjiconv-0.4.0.tar.gz
Size 124.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4548c7ab697054663e0df886b39d24a8f3515602b3a172264d32f904007659f5
BLAKE2b-256 checksum
How to use checksums
bfaca63b5edb11c784e604b0f8bf21c88117b09d47d233734dbd0d833e0d4da3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / kanjiconv-0.4.0-py3-none-any.whl

Download URL kanjiconv-0.4.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cccd5d649333570c5573c2415c39a36b58d553197b6e0654fbe23e43b1b36bcb
BLAKE2b-256 checksum
How to use checksums
3718d3e7717591024b881000925435d7cd59bb33ff62bcc94c78966faf9a2cbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for kanjiconv 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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