PyEnchant

3.3.0 · active · verified Thu Apr 09

PyEnchant is a Python library providing bindings for the Enchant spellchecking system. It allows developers to check the spelling of words, suggest corrections, and manage dictionaries for various languages. The current version is 3.3.0, and the library maintains an active release cadence, with updates addressing Python version compatibility and bug fixes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize a dictionary for a specific language (e.g., American English), check the spelling of words, and retrieve spelling suggestions for misspelled words. It includes error handling for missing dictionaries or the Enchant C library.

import enchant

try:
    # Initialize a dictionary for American English
    # Replace 'en_US' with your desired language tag
    # Ensure the corresponding Enchant dictionaries are installed on your system
    d = enchant.Dict("en_US")

    # Check if a word is spelled correctly
    word_correct = "hello"
    print(f"'{word_correct}' is spelled correctly: {d.check(word_correct)}")

    word_incorrect = "helllo"
    print(f"'{word_incorrect}' is spelled correctly: {d.check(word_incorrect)}")

    # Get suggestions for a misspelled word
    suggestions = d.suggest(word_incorrect)
    print(f"Suggestions for '{word_incorrect}': {suggestions}")

except enchant.errors.DictNotFoundError:
    print("Error: Dictionary for the specified language was not found.")
    print("Please ensure the Enchant C library and relevant language dictionaries are installed.")
except enchant.errors.EnchantError as e:
    print(f"An Enchant error occurred: {e}")
    print("Ensure the Enchant C library is properly installed and accessible.")

view raw JSON →