Registry / ai-ml / pythainlp

pythainlp

JSON →
library5.3.7pypypi✓ verified 25d ago

PyThaiNLP is a Python library for natural language processing (NLP) of the Thai language. It provides standard NLP functions like word and sentence segmentation, part-of-speech tagging, transliteration, and various utilities. The library is actively maintained, with version 5.3.4 as the current stable release, and new minor updates for the 5.x series are still being released, with a major 6.0 release expected to introduce breaking changes.

pip install pythainlp
INSTALL
IMPORT
SIG · PYTHAINLP
P
pythainlp
ai-mlpythonv5.3.7
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.3.7 · 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
glibc
py 3.10
1/3 runs
1/3 runs
py 3.11
1/3 runs
1/3 runs
py 3.12
1/3 runs
1/3 runs
py 3.13
1/3 runs
1/3 runs
py 3.9
1/3 runs
1/3 runs
Code
Verified usage

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

word_tokenize
from pythainlp.tokenize import word_tokenize
sent_tokenize
from pythainlp.tokenize import sent_tokenize
is_thai
from pythainlp.morpheme import is_thai
from pythainlp.util import is_thai
Moved from `pythainlp.util` to `pythainlp.morpheme` in PyThaiNLP 5.0.

This quickstart demonstrates basic word and sentence tokenization using PyThaiNLP's default engine. Many other tokenization engines are available and can be specified with the `engine` parameter (e.g., `engine="icu"`).

from pythainlp.tokenize import word_tokenize text = "ฉันรักภาษาไทย" tokens = word_tokenize(text) print(tokens) # Output example: ['ฉัน', 'รัก', 'ภาษาไทย'] sentences = sent_tokenize("สวัสดีครับ. สบายดีไหมครับ?") print(sentences) # Output example: ['สวัสดีครับ.', 'สบายดีไหมครับ?']
Debug
Known issues
breakingThe upcoming PyThaiNLP 6.0 release is expected to introduce breaking changes. The minimum required Python version for PyThaiNLP 5.x and upcoming 6.x is Python 3.9+.
fix
Review the migration guide for PyThaiNLP 6.0 when it's released and ensure your environment uses Python 3.9 or newer.
affects: 5.x (upcoming 6.0)
deprecatedEnvironment variables `PYTHAINLP_DATA_DIR` and `PYTHAINLP_READ_MODE` are deprecated. Use `PYTHAINLP_DATA` to specify the data directory and `PYTHAINLP_READ_ONLY` for read-only mode. Setting both deprecated and new versions simultaneously will raise a `ValueError`.
fix
Update environment variable usage: `PYTHAINLP_DATA` instead of `PYTHAINLP_DATA_DIR`, and `PYTHAINLP_READ_ONLY` instead of `PYTHAINLP_READ_MODE`.
affects: 4.x+
gotchaPyThaiNLP lazy-loads word lists and other resources. This can result in a "cold start" delay during the first function call, especially for tokenizers. Subsequent calls will perform at full speed.
fix
Be aware of this initial delay in performance-sensitive applications. Consider pre-loading necessary models or data if consistent, immediate response times are critical.
affects: 5.x+
gotchaInstalling optional dependencies like `PyICU` (for the `icu` extra) on Windows can be challenging. It may require finding pre-built wheel packages or setting the `ICU_VERSION` environment variable for a source build. Additionally, `python-crfsuite` (a dependency for some features) has known build issues with Python 3.10+.
fix
For PyICU on Windows, check `https://www.lfd.uci.edu/~gohlke/pythonlibs/` for pre-built wheels. For `python-crfsuite` on Python 3.10+, refer to PyThaiNLP's FAQ for workarounds or ensure you're using a compatible Python version or installation method for that dependency.
affects: All versions, specifically on Windows or Python 3.10+
gotchaWhen using PyThaiNLP in distributed computing environments (e.g., Apache Spark), the `PYTHAINLP_DATA` environment variable must be set *inside* the function that will be distributed to worker nodes, not in the driver program. The default data directory (`~/pythainlp-data`) may not be writable on executor nodes, leading to `PermissionError`.
fix
Set `PYTHAINLP_DATA` to a writable local directory (e.g., `./pythainlp-data`) within the distributed function on each worker node before any data access.
affects: All versions in distributed environments
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pythainlp'
The PyThaiNLP library is not installed in the current Python environment.
fix
pip install pythainlp
FileNotFoundError: [Errno 2] No such file or directory: '/Users/username/.pythainlp/data/models/...' (or similar path)
A required model for a specific PyThaiNLP function, such as a word segmenter or part-of-speech tagger, has not been downloaded or cannot be found.
fix
Download the necessary model(s) using `pythainlp.tools.download("model_name")`, replacing `model_name` with the specific model needed (e.g., "attacut", "perceptron_tagger").
ModuleNotFoundError: No module named 'tltk'
The `tltk` library, an optional dependency for some PyThaiNLP word segmentation engines, has not been installed.
fix
Install the `tltk` dependency separately: `pip install tltk`.
ImportError: cannot import name 'word_tokenize' from 'pythainlp'
The `word_tokenize` function is located within the `pythainlp.tokenize` submodule, not directly under the `pythainlp` package.
fix
Import `word_tokenize` from the correct submodule: `from pythainlp.tokenize import word_tokenize`.
Upgrade
Version history
5.3.7latest on PyPI · released Aug 14, 2026
Audit
Dependencies
tzdataoptionalRequired for some functionalities on Windows systems.
PyICUoptionalRequired for 'icu' extra; installation on Windows can be complex (needs pre-built wheels or manual build).
Agent activity
37 hits · last 30 days
node
34
OpenAI (training)
1
Resources
pythainlp — pip install pythainlp · libregistry