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.

Metadata

Release files for kotoshu 0.1.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 kotoshu 0.1.0
File Size Uploaded Provenance
kotoshu-0.1.0.tar.gz 9.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kotoshu 0.1.0
File Interpreter ABI Platform
kotoshu-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / kotoshu-0.1.0.tar.gz

Download URL kotoshu-0.1.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cde6d099809f7d6a52fd507089d0a788a73d954554a57c7182e1b45a1930ec02
BLAKE2b-256 checksum
How to use checksums
5235e02dbe27db14db3f96762dbadcb830af45a28c792abf837b63e5ec4c83ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.5

Release files / kotoshu-0.1.0-py3-none-any.whl

Download URL kotoshu-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2837aa106ea5862327a8e7729c504b4521b0c12dcf1859eb6b1d588bc305d09f
BLAKE2b-256 checksum
How to use checksums
96ab8b4ffd258631171f8f69febcca33cd3d63e21dd43835614b198ca2bc3e17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.5

Security for kotoshu 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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