Skip to main content

SudachiPy

PyPi version Documentation

SudachiPy is a Python version of Sudachi, a Japanese morphological analyzer.

This is not a pure Python implementation, but bindings for the Sudachi.rs.

IMPORTANT v0.7 introduces a new dictionary binary format (V1). When upgrading from v0.6, update the system dictionary and rebuild all user dictionaries against the exact system dictionary that will be used at runtime. If you download dictionaries from a pinned URL, update it. See the migration guide.

CAUTION SudachiDict-* does not provide V1 dictionary yet (we are planning to support V1 from v202610xx). You need to download V1 dictionary binary by yourself and explicitly specify its path.

CAUTION Release v0.7.* is unstable. It may include breaking changes even between patch versions, so please pin the exact version and review release notes carefully before upgrading.

TL;DR

$ pip install sudachipy sudachidict_core

$ echo "高輪ゲートウェイ駅" | sudachipy
高輪ゲートウェイ駅	名詞,固有名詞,一般,*,*,*	高輪ゲートウェイ駅
EOS

$ echo "高輪ゲートウェイ駅" | sudachipy -m A
高輪	名詞,固有名詞,地名,一般,*,*	高輪
ゲートウェイ	名詞,普通名詞,一般,*,*,*	ゲートウェー
駅	名詞,普通名詞,一般,*,*,*	駅
EOS

$ echo "空缶空罐空きカン" | sudachipy -a
空缶	名詞,普通名詞,一般,*,*,*	空き缶	空缶	アキカン	0
空罐	名詞,普通名詞,一般,*,*,*	空き缶	空罐	アキカン	0
空きカン	名詞,普通名詞,一般,*,*,*	空き缶	空きカン	アキカン	0
EOS
from sudachipy import Dictionary, SplitMode

tokenizer = Dictionary().tokenizer()

morphemes = tokenizer.tokenize("国会議事堂前駅")
print(morphemes[0].surface())  # '国会議事堂前駅'
print(morphemes[0].reading_form())  # 'コッカイギジドウマエエキ'
print(morphemes[0].part_of_speech())  # ['名詞', '固有名詞', '一般', '*', '*', '*']

morphemes = tokenizer.tokenize("国会議事堂前駅", SplitMode.A)
print([m.surface() for m in morphemes])  # ['国会', '議事', '堂', '前', '駅']

Setup

You need SudachiPy and a dictionary.

Step 1. Install SudachiPy

pip install sudachipy

Step 2. Get a Dictionary

You can get dictionary as a Python package. It may take a while to download the dictionary file (around 70MB for the core edition).

pip install sudachidict_core

Alternatively, you can choose other dictionary editions. See this section for the detail.

Usage: As a command

There is a CLI command sudachipy.

$ echo "外国人参政権" | sudachipy
外国人参政権	名詞,普通名詞,一般,*,*,*	外国人参政権
EOS
$ echo "外国人参政権" | sudachipy -m A
外国	名詞,普通名詞,一般,*,*,*	外国
人	接尾辞,名詞的,一般,*,*,*	人
参政	名詞,普通名詞,一般,*,*,*	参政
権	接尾辞,名詞的,一般,*,*,*	権
EOS
$ sudachipy tokenize -h
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-s string]
                          [-a] [-d] [-v]
                          [file [file ...]]

Tokenize Text

positional arguments:
  file           text written in utf-8

optional arguments:
  -h, --help     show this help message and exit
  -r file        the setting file in JSON format
  -m {A,B,C}     the mode of splitting
  -o file        the output file
  -s string      sudachidict type
  -a             print all of the fields
  -d             print the debug information
  -v, --version  print sudachipy version

Note: The Debug option (-d) is disabled in version 0.6.*

Output

Columns are tab separated.

  • Surface
  • Part-of-Speech Tags (comma separated)
  • Normalized Form

When you add the -a option, it additionally outputs

  • Dictionary Form
  • Reading Form
  • Dictionary ID
    • 0 for the system dictionary
    • 1 and above for the user dictionaries
    • -1 if a word is Out-of-Vocabulary (not in the dictionary)
  • Synonym group IDs
  • (OOV) if a word is Out-of-Vocabulary (not in the dictionary)
$ echo "外国人参政権" | sudachipy -a
外国人参政権	名詞,普通名詞,一般,*,*,*	外国人参政権	外国人参政権	ガイコクジンサンセイケン	0	[]
EOS
echo "阿quei" | sudachipy -a
阿	名詞,普通名詞,一般,*,*,*	阿	阿		-1	[]	(OOV)
quei	名詞,普通名詞,一般,*,*,*	quei	quei		-1	[]	(OOV)
EOS

Usage: As a Python package

API

See API reference page.

Example

from sudachipy import Dictionary, SplitMode

tokenizer_obj = Dictionary().tokenizer()
# Multi-granular Tokenization

# SplitMode.C is the default mode
[m.surface() for m in tokenizer_obj.tokenize("国家公務員", SplitMode.C)]
# => ['国家公務員']

[m.surface() for m in tokenizer_obj.tokenize("国家公務員", SplitMode.B)]
# => ['国家', '公務員']

[m.surface() for m in tokenizer_obj.tokenize("国家公務員", SplitMode.A)]
# => ['国家', '公務', '員']
# Morpheme information

m = tokenizer_obj.tokenize("食べ")[0]

m.surface() # => '食べ'
m.dictionary_form() # => '食べる'
m.reading_form() # => 'タベ'
m.part_of_speech() # => ['動詞', '一般', '*', '*', '下一段-バ行', '連用形-一般']
# Normalization

tokenizer_obj.tokenize("附属", mode)[0].normalized_form()
# => '付属'
tokenizer_obj.tokenize("SUMMER", mode)[0].normalized_form()
# => 'サマー'
tokenizer_obj.tokenize("シュミレーション", mode)[0].normalized_form()
# => 'シミュレーション'

(With 20210802 core dictionary. The results may change when you use other versions)

Dictionary Edition

There are three editions of Sudachi Dictionary, namely, small, core, and full. See WorksApplications/SudachiDict for the detail.

SudachiPy uses sudachidict_core by default.

Dictionaries can be installed as Python packages sudachidict_small, sudachidict_core, and sudachidict_full.

The dictionary files are not in the package itself, but it is downloaded upon installation.

IMPORTANT After v20260723, SudachiDict-* will provide the dictionary in V1 binary format. You can only use latter versions with SudachiPy v0.7, and you can only use that or former versions with SudachiPy v0.6.

Dictionary option: command line

You can specify the dictionary with the tokenize option -s.

$ pip install sudachidict_small
$ echo "外国人参政権" | sudachipy -s small
$ pip install sudachidict_full
$ echo "外国人参政権" | sudachipy -s full

Dictionary option: Python package

You can specify the dictionary with the Dicionary() argument; config or dict.

class Dictionary(config=None, resource_dir=None, dict=None)
  1. config
    • You can specify the file path to the setting file with config (See [Dictionary in The Setting File](#Dictionary in The Setting File) for the detail).
    • If the dictionary file is specified in the setting file as systemDict, SudachiPy will use the dictionary.
  2. dict
    • You can also specify the dictionary type with dict.
    • The available arguments are small, core, full, or a path to the dictionary file.
    • If different dictionaries are specified with config and dict, a dictionary defined dict overrides those defined in the config.
from sudachipy import Dictionary

# default: sudachidict_core
tokenizer_obj = Dictionary().tokenizer()

# The dictionary given by the `systemDict` key in the config file (/path/to/sudachi.json) will be used
tokenizer_obj = Dictionary(config="/path/to/sudachi.json").tokenizer()

# The dictionary specified by `dict` will be used.
tokenizer_obj = Dictionary(dict="core").tokenizer()  # sudachidict_core (same as default)
tokenizer_obj = Dictionary(dict="small").tokenizer()  # sudachidict_small
tokenizer_obj = Dictionary(dict="full").tokenizer()  # sudachidict_full

# The dictionary specified by `dict` overrides those defined in the config.
# In the following code, `sudachidict_full` will be used regardless of a dictionary defined in the config file.
tokenizer_obj = Dictionary(config="/path/to/sudachi.json", dict="full").tokenizer()

Dictionary in The Setting File

Alternatively, if the dictionary file is specified in the setting file, sudachi.json, SudachiPy will use that file.

{
    "systemDict" : "relative/path/from/resourceDir/to/system.dic",
    ...
}

The default setting file is sudachi.json. You can specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

User Dictionary

To use a user dictionary, user.dic, place sudachi.json to anywhere you like, and add userDict value with the relative path from sudachi.json to your user.dic.

{
    "userDict" : ["relative/path/to/user.dic"],
    ...
}

Then specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

You can build a user dictionary with the subcommand ubuild.

$ sudachipy ubuild -h
usage: sudachipy ubuild [-h] [-o file] [-d string] -s file file [file ...]

Build User Dictionary

positional arguments:
  file        source files with CSV format (one or more)

options:
  -h, --help  show this help message and exit
  -o file     output file (default: user.dic)
  -d string   description comment to be embedded on dictionary

required named arguments:
  -s file     system dictionary path

About the dictionary file format, please refer to this document (written in Japanese, English version is not available yet).

Customized System Dictionary

$ sudachipy build -h
usage: sudachipy build [-h] [-o file] [-d string] -m file file [file ...]

Build Sudachi Dictionary

positional arguments:
  file        source files with CSV format (one of more)

optional arguments:
  -h, --help  show this help message and exit
  -o file     output file (default: system.dic)
  -d string   description comment to be embedded on dictionary

required named arguments:
  -m file     connection matrix file with MeCab's matrix.def format

To use your customized system.dic, place sudachi.json to anywhere you like, and overwrite systemDict value with the relative path from sudachi.json to your system.dic.

{
    "systemDict" : "relative/path/to/system.dic",
    ...
}

Then specify your sudachi.json with the -r option.

$ sudachipy -r path/to/sudachi.json

Binary wheels

We provide binary builds for macOS (10.14+), Windows and Linux x86_64/aarch64 architecture. x86 32-bit architecture is not supported and is not tested. MacOS source builds seem to work on ARM-based (Aarch64) Macs, but this architecture also is not tested and require installing Rust toolchain and Cargo.

More information here.

For Developers

Build from source

Install sdist via pip

  1. Install uv.
  2. Run python/build-sdist.sh from the repository root.
    • source distribution will be generated under python/dist/ dir.
  3. Install it via pip: pip install ./python/dist/SudachiPy-[version].tar.gz

Install develop build

  1. Install uv.
  2. Run uv pip install -e . from the repository root to install sudachipy (editable install).
  3. Now you can import the module by import sudachipy.

ref: maturin

Test

Run python/build_and_test.sh to run the tests.

Contact

Sudachi and SudachiPy are developed by WAP Tokushima Laboratory of AI and NLP.

Open an issue, or come to our Slack workspace for questions and discussion.

https://sudachi-dev.slack.com/ (Get invitation here)

Enjoy tokenization!

Metadata

Release files for SudachiPy 0.7.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 SudachiPy 0.7.0
File Size Uploaded
sudachipy-0.7.0.tar.gz 304.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for SudachiPy 0.7.0
File
sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details
sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64 Details
sudachipy-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
sudachipy-0.7.0-cp314-cp314t-macosx_10_15_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.15+ x86-64 Details
sudachipy-0.7.0-cp314-cp314t-macosx_10_15_universal2.whl CPython 3.14 CPython 3.14 free-threading macOS 10.15+ universal2 (ARM64, x86-64) Details
sudachipy-0.7.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
sudachipy-0.7.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
sudachipy-0.7.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
sudachipy-0.7.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
sudachipy-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details
sudachipy-0.7.0-cp310-abi3-macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) Details

Total release size: 21.4 MB

Release files / sudachipy-0.7.0.tar.gz

Download URL sudachipy-0.7.0.tar.gz
Size 304.7 kB
Tags Source
SHA-256 checksum
How to use checksums
14a2505e7d086fe9da64c0048d8e2de13cdded3aac4f1e047929cef51dba338c
BLAKE2b-256 checksum
How to use checksums
fc1db34702f38a8bd34972836538d222209095d5aba7faff79d56bce3fb2640c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c8306eab503d891e394fb21156e417c2f9f54cc39f56dddb8cf2b40620d470fa
BLAKE2b-256 checksum
How to use checksums
2df42df0f7a5dce327d82c451be96151afa8f7e3324a3a8d71845eec5be26f3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_aarch64.whl

Download URL sudachipy-0.7.0-cp314-cp314t-manylinux_2_28_aarch64.whl
Size 1.7 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
f1e24f71a71816dcbc6fb759a5819cca5d603a4d49b7ade63dd0fe49468ed22c
BLAKE2b-256 checksum
How to use checksums
cf395e138a2f949bf3af45951980382adc69d0d975448e604dc1801325f0008a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl

Download URL sudachipy-0.7.0-cp314-cp314t-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9446eba17985b1d14926afc6312fb0367687ab1b5397fa65d7e2cdd1745451c9
BLAKE2b-256 checksum
How to use checksums
8b75952595fe7fa84a8f90cbe8f94a7cb5210642f166ec0ec1d7d808abef978e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp314-cp314t-macosx_10_15_x86_64.whl

Download URL sudachipy-0.7.0-cp314-cp314t-macosx_10_15_x86_64.whl
Size 1.6 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
efd56375584dec9523fe9a26daa69da02a70ae2f2c22d25248e65a4998cae8e1
BLAKE2b-256 checksum
How to use checksums
62204475da1e0393bef7d136f91214d560730006d2a4792e585003b17f2779e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp314-cp314t-macosx_10_15_universal2.whl

Download URL sudachipy-0.7.0-cp314-cp314t-macosx_10_15_universal2.whl
Size 3.1 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
1bf2254ee6357e0defa498630f188fefa8a543b82887077cfb1596bc3e8d4840
BLAKE2b-256 checksum
How to use checksums
f2f7580ece6a559e0cad8a9a3fff36bbd478e335e125c96c1910abe20f3b6bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-win_amd64.whl

Download URL sudachipy-0.7.0-cp310-abi3-win_amd64.whl
Size 1.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8d0429db2d02d408daa7dccd062a6d8c2984a07f8e448b49a3ea694377617658
BLAKE2b-256 checksum
How to use checksums
e9a103e40b0eadbdd48ed47aef7aaf27d4703f5cc225750872af1a26de08ec2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL sudachipy-0.7.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
dfc90631aa2276d2165e1995bc94b56c9f5bc27b875f43fb7d67e4a3b7346d4f
BLAKE2b-256 checksum
How to use checksums
1d2db2c2511b3627032e81ef1626d6bce4506efacc7b698ca0e70cf6b4345e86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL sudachipy-0.7.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
68be139f5d7f053eba16fd3f792e4ef0c6bfed81a1b63e68b4544c7159296034
BLAKE2b-256 checksum
How to use checksums
9f125455c3e4afea272c1ef0995c489dc9c2a6ead2a6d980822a53ae879a2042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL sudachipy-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0e60cefd3a7a9680206ae160bf86d266d0d60e434adac2384f8c7a6dfb0f3ba7
BLAKE2b-256 checksum
How to use checksums
88113b740eea1796d1ce6f7bdaa1f5470685dbcbfcacf751f3aa06d9da72856f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL sudachipy-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
907eadc1db305f9bc6e502a9acf9ff1ac871cd8d4ac3a2e0aaba3ddc60e93b2a
BLAKE2b-256 checksum
How to use checksums
d7b32117420a05b2785ce561912baff01dd7872f5bca6b60dce49dc592a9f600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sudachipy-0.7.0-cp310-abi3-macosx_10_12_universal2.whl

Download URL sudachipy-0.7.0-cp310-abi3-macosx_10_12_universal2.whl
Size 3.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
6be34e856c99498e990904f7155e1a102f675cf5edfdaf7a396f26d71ce4b333
BLAKE2b-256 checksum
How to use checksums
44aa47edbec02618803ac8ef8f1561b233760bbd266fb040ba9d4d577a5f1773
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

0.7.0 This release

12 release files

0.6.9

18 release files

0.6.8

19 release files

0.6.7

16 release files

0.6.6

13 release files

0.6.5

13 release files

0.6.4

13 release files

0.6.3

16 release files

0.6.0

16 release files

0.5.4

10 release files

0.5.3

10 release files

0.5.2

10 release files

0.5.0

10 release files

0.4.9

10 release files

0.4.8

1 release file

0.4.7

1 release file

0.4.6

4 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.13

2 release files

0.3.12

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2.1

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