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.13

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.3.2

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.3.2
File Size Uploaded Provenance
kanjiconv-0.3.2.tar.gz 117.3 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 136.1 kB

Release files / kanjiconv-0.3.2.tar.gz

Download URL kanjiconv-0.3.2.tar.gz
Size 117.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f3b9b94813d6b9052578c404ce90aeebe1c78ea217efbfb60d4ad8207792abfd
BLAKE2b-256 checksum
How to use checksums
8693180613c7e3876c274c75b0ab4be8cd9bd1d95a194b9467db78a80c754268
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.3.2-py3-none-any.whl

Download URL kanjiconv-0.3.2-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
933fd0f478cba92a069b11f109a574b49bc78e18739c6ecbe8fa4d102948e244
BLAKE2b-256 checksum
How to use checksums
a6f0e803717ec6b50cae3b1e4d866c89661b2845d8f64c2cd4ad8834bb798d76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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.3.2

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.

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