LanguageTool Python Wrapper

3.3.0 · active · verified Thu Apr 16

language_tool_python is an actively maintained Python wrapper for LanguageTool, an open-source grammar, style, and spell checker. It facilitates grammar checking by either running a local LanguageTool Java server, utilizing the public LanguageTool API, or connecting to a custom remote LanguageTool server. The library sees regular minor and patch releases, ensuring active development and updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `language-tool-python` with both a local LanguageTool server (which requires a Java JRE) and the public LanguageTool API. It checks a sample sentence for grammar errors and applies corrections. The `with` statement is recommended for proper resource management.

import language_tool_python

# For local server (requires Java JRE installed)
# Ensure Java Runtime Environment (JRE) is installed and accessible in your PATH
try:
    with language_tool_python.LanguageTool('en-US') as tool:
        text = "This are a example of bad grammer."
        matches = tool.check(text)
        print("Original text:", text)
        print("Detected errors:", matches)
        corrected_text = tool.correct(text)
        print("Corrected text:", corrected_text)
except Exception as e:
    print(f"Could not initialize local LanguageTool server: {e}")
    print("Trying public API...")

# For public LanguageTool API
# Note: Public API has rate limits. For heavy usage, consider a local/remote server.
try:
    with language_tool_python.LanguageToolPublicAPI('en-US') as tool:
        text_public = "He don't like it."
        matches_public = tool.check(text_public)
        print("\nOriginal text (Public API):", text_public)
        print("Detected errors (Public API):", matches_public)
        corrected_text_public = tool.correct(text_public)
        print("Corrected text (Public API):", corrected_text_public)
except Exception as e:
    print(f"Could not use public LanguageTool API: {e}")
    print("Check your internet connection or API rate limits.")

view raw JSON →