kotoshu-python
Python client for the Kotoshu HTTP spell-check API.
Install
pip install kotoshu
Quick start
from kotoshu import Client
client = Client("http://localhost:9292")
# Check a document
result = client.check("helo wrold", language="en")
for err in result.errors:
print(f"{err.word} -> {err.top_suggestions}")
# Suggestions for one word
for sug in client.suggest("helo", max_suggestions=3):
print(sug.word, sug.confidence)
# Language detection
det = client.detect("bonjour le monde")
print(det.language, det.confidence)
Reference
Client(base_url, *, language="en", timeout=30.0, session=None)
health() -> dictlanguages() -> list[str]check(text, *, language=None, fmt="full") -> DocumentResultsuggest(word, *, language=None, max_suggestions=None) -> list[Suggestion]detect(text) -> Detectioncorrect(word, *, language=None) -> bool
Result types
DocumentResult:file,word_count,errors: list[WordError],success,misspelled_wordsWordError:word,position,suggestions: list[Suggestion],top_suggestionsSuggestion:word,distance,confidence,source,metadataDetection:language,confidence
Exceptions
KotoshuError: baseResourceNotSetupError: server returned 422 — language not set up
Native backend (optional, offline)
kotoshu can also spell-check fully offline through the native Rust
engine instead of the HTTP API. The engine ships in the
kotoshu-native wheel (module
kotoshu_native) and works on local Hunspell dictionaries:
from kotoshu.native import dictionary
d = dictionary("en_US.aff", "en_US.dic")
d.correct("hello") # True
d.suggest("hlelo", max_suggestions=3) # [Suggestion(word="hello", ...)]
Dictionary.correct/suggest return exactly the same types as the HTTP
Client (bool and list[Suggestion]), so result handling is identical
across backends. The offline engine is word-level only: no document
parsing, no language detection.
KOTOSHU_BACKEND
auto(default): native whenkotoshu_nativeis importable, else HTTPnative: require the native engine (NativeUnavailableErrorwhen missing)http: always the HTTP API
kotoshu.backend() reports the backend in effect ("native" or
"http"); kotoshu.native.available() whether the wheel is importable.
Getting the wheel
The kotoshu-native wheel is not published to PyPI yet (publishing
is blocked on owner credentials), so pip install kotoshu[native]
resolves only after that first publish. Until then build it locally from
the kotoshu-rs repository:
python3 -m venv .venv && . .venv/bin/activate
pip install maturin
cd /path/to/kotoshu-rs/kotoshu-python
maturin develop
Without the wheel nothing changes: auto silently uses HTTP and the
client behaves exactly as before.
License
BSD-2-Clause, same as Kotoshu.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kotoshu-0.1.0.tar.gz.
File metadata
- Download URL: kotoshu-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cde6d099809f7d6a52fd507089d0a788a73d954554a57c7182e1b45a1930ec02
|
|
| MD5 |
7fb5ad39667179ef2c75f926c5588a8e
|
|
| BLAKE2b-256 |
5235e02dbe27db14db3f96762dbadcb830af45a28c792abf837b63e5ec4c83ed
|
File details
Details for the file kotoshu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kotoshu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2837aa106ea5862327a8e7729c504b4521b0c12dcf1859eb6b1d588bc305d09f
|
|
| MD5 |
4aea530aada1caf3cd37de0c1d3975f4
|
|
| BLAKE2b-256 |
96ab8b4ffd258631171f8f69febcca33cd3d63e21dd43835614b198ca2bc3e17
|