Skip to main content

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() -> dict
  • languages() -> list[str]
  • check(text, *, language=None, fmt="full") -> DocumentResult
  • suggest(word, *, language=None, max_suggestions=None) -> list[Suggestion]
  • detect(text) -> Detection
  • correct(word, *, language=None) -> bool

Result types

  • DocumentResult: file, word_count, errors: list[WordError], success, misspelled_words
  • WordError: word, position, suggestions: list[Suggestion], top_suggestions
  • Suggestion: word, distance, confidence, source, metadata
  • Detection: language, confidence

Exceptions

  • KotoshuError: base
  • ResourceNotSetupError: 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 when kotoshu_native is importable, else HTTP
  • native: require the native engine (NativeUnavailableError when 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

kotoshu-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kotoshu-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

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

Hashes for kotoshu-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cde6d099809f7d6a52fd507089d0a788a73d954554a57c7182e1b45a1930ec02
MD5 7fb5ad39667179ef2c75f926c5588a8e
BLAKE2b-256 5235e02dbe27db14db3f96762dbadcb830af45a28c792abf837b63e5ec4c83ed

See more details on using hashes here.

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

Hashes for kotoshu-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2837aa106ea5862327a8e7729c504b4521b0c12dcf1859eb6b1d588bc305d09f
MD5 4aea530aada1caf3cd37de0c1d3975f4
BLAKE2b-256 96ab8b4ffd258631171f8f69febcca33cd3d63e21dd43835614b198ca2bc3e17

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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