Registry / ai-ml / pykakasi

pykakasi

JSON →
library2.3.0pypypi✓ verified 26d ago

pykakasi is a Python Natural Language Processing (NLP) library that transliterates Japanese text (hiragana, katakana, and kanji) into rōmaji (Latin/Roman alphabet). It supports NFC-normalized characters and is based on the C-language kakasi library. The current version is 2.3.0, and while there isn't a strict release cadence, updates are made as needed.

pip install pykakasi
INSTALL
IMPORT
SIG · PYKAKASI
P
pykakasi
ai-mlpythonv2.3.0
Install
2.2s avg
Import
320ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.330s · 28.3MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.2s · import 0.310s · 29MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

kakasi
✓ from pykakasi import kakasi
✗ from pykakasi import kakasi, wakati; k = kakasi(); k.setMode(...); conv = k.getConverter()
The `setMode()`, `getConverter()`, and `do()` methods (old API) are deprecated and will be removed in v3.0. Use the `kakasi().convert()` method for modern usage.

Initializes the kakasi converter and demonstrates both the deprecated (v1.x) and the recommended (v2.x) API for converting Japanese text into romaji, hiragana, and katakana. The new API offers a more streamlined `convert()` method.

import pykakasi kks = pykakasi.kakasi() text = "かな漢字交じり文" # Configure conversion modes (optional, defaults to Hepburn romaji, no spaces) kks.setMode('H', 'a') # Hiragana to romaji kks.setMode('K', 'a') # Katakana to romaji kks.setMode('J', 'a') # Kanji to romaji kks.setMode('r', 'Hepburn') # Use Hepburn Romanization kks.setMode('s', True) # Add spaces kks.setMode('C', True) # Capitalize converter = kks.getConverter() result_old_api = converter.do(text) print(f"Old API result: {result_old_api}") # Recommended new API (v2.0.0+) result_new_api = pykakasi.kakasi().convert(text) print("\nNew API result (default modes):") for item in result_new_api: print(f"Original: {item['orig']}, Kana: {item['kana']}, Hiragana: {item['hira']}, Romaji: {item['hepburn']}")
pykakasi --version
Debug
Known issues
deprecatedThe old API methods (`setMode()`, `getConverter()`, `do()`, and the `wakati` class) are deprecated in pykakasi v2.1.0 and will be removed entirely in v3.0. Migrate to the `kakasi().convert()` method for future compatibility.
fix
Rewrite code using `kakasi().convert(text)` for conversion. For custom options, `kakasi` can be configured before calling `convert` or by passing a dictionary of options to its constructor (refer to official docs for full options).
affects: >=2.1.0
gotchapykakasi is distributed under the GNU General Public License v3.0 or later (GPLv3+). This license has implications for commercial use, potentially requiring source code disclosure if the library is incorporated into proprietary software.
fix
Review your project's licensing requirements. If GPLv3+ is incompatible, consider alternative Japanese romanization libraries with more permissive licenses (e.g., MIT or BSD).
affects: All versions
gotchaThe library primarily expects Unicode characters in Normalization Form C (NFC). Using text in Normalization Form D (NFD) might lead to incorrect or unexpected conversion results due to separated diacritics.
fix
Ensure input text is normalized to NFC before processing with pykakasi, e.g., using `unicodedata.normalize('NFC', text)`.
affects: All versions
gotchaThe original GitHub repository (miurahr/pykakasi) was archived in July 2022 and now points to Codeberg. Users looking for the official source or contributing should refer to the Codeberg repository.
fix
Use `https://codeberg.org/miurahr/pykakasi` as the primary source for the project, documentation, and issue tracking.
affects: All versions
gotchaAccording to some analyses (e.g., Snyk report mentioned in a blog post), the project's maintenance status has been rated as 'Inactive,' despite its continued widespread usage. This might indicate slower response times for issues or new feature development.
fix
Be aware of the potential for slower maintenance. For mission-critical applications requiring active development or immediate support, evaluate the project's current activity or consider alternatives.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pykakasi'
The pykakasi library is not installed in your Python environment or your Python interpreter cannot find it.
fix
Install the library using pip: `pip install pykakasi` or `conda install -c conda-forge pykakasi` if using Anaconda/Miniconda.
TypeError: 'module' object is not callable
This error occurs when you try to call the `pykakasi` module itself as a function, instead of instantiating the `kakasi` class within the module.
fix
Correctly instantiate the `kakasi` class: `import pykakasi; kks = pykakasi.kakasi()`
AttributeError: 'kakasi' object has no attribute 'setMode'
You are using deprecated API methods (`setMode()`, `getConverter()`, `do()`) that were part of pykakasi v1.2. These methods are deprecated in v2.1.0 and will be removed in v3.0, leading to this error if used in newer versions of the library.
fix
Migrate your code to use the modern API, specifically the `kakasi().convert(text)` method for transliteration. For example: `import pykakasi; kks = pykakasi.kakasi(); result = kks.convert(text)`
ImportError: No module named nose
This error typically occurs during the installation process (`pip install pykakasi`) in older Python environments, often when `nose` (a testing framework dependency for pykakasi's setup.py) is not installed.
fix
Ensure you have a modern Python environment (Python 3.8+ is officially supported by pykakasi v2.3.0). If the issue persists, try installing `nose` separately before installing pykakasi: `pip install nose` or consider upgrading pip itself. Alternatively, installing from a reliable package manager like conda-forge (`conda install -c conda-forge pykakasi`) might resolve dependency issues.
Upgrade
Version history
2.3.0latest on PyPI · released Jun 24, 2024
Audit
Dependencies
kleptorequiredProvides a mapping database for the library's functionality.
Agent activity
11 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
pykakasi — pip install pykakasi · libregistry