Skip to main content

pyspellchecker

https://badge.fury.io/py/pyspellchecker.svg https://travis-ci.org/barrust/pyspellchecker.svg?branch=master https://coveralls.io/repos/github/barrust/pyspellchecker/badge.svg?branch=master Downloads

Pure Python Spell Checking based on Peter Norvig’s blog post on setting up a simple spell checking algorithm.

It uses a Levenshtein Distance algorithm to find permutations within an edit distance of 2 from the original word. It then compares all permutations (insertions, deletions, replacements, and transpositions) to known words in a word frequency list. Those words that are found more often in the frequency list are more likely the correct results.

pyspellchecker supports multiple languages including English, Spanish, German, French, and Portuguese. Dictionaries were generated using the WordFrequency project on GitHub.

pyspellchecker supports Python 3 and Python 2.7 but, as always, Python 3 is the preferred version!

pyspellchecker allows for the setting of the Levenshtein Distance to check. For longer words, it is highly recommended to use a distance of 1 and not the default 2. See the quickstart to find how one can change the distance parameter.

Installation

The easiest method to install is using pip:

pip install pyspellchecker

To install from source:

git clone https://github.com/barrust/pyspellchecker.git
cd pyspellchecker
python setup.py install

As always, I highly recommend using the Pipenv package to help manage dependencies!

Quickstart

After installation, using pyspellchecker should be fairly straight forward:

from spellchecker import SpellChecker

spell = SpellChecker()

# find those words that may be misspelled
misspelled = spell.unknown(['something', 'is', 'hapenning', 'here'])

for word in misspelled:
    # Get the one `most likely` answer
    print(spell.correction(word))

    # Get a list of `likely` options
    print(spell.candidates(word))

If the Word Frequency list is not to your liking, you can add additional text to generate a more appropriate list for your use case.

from spellchecker import SpellChecker

spell = SpellChecker()  # loads default word frequency list
spell.word_frequency.load_text_file('./my_free_text_doc.txt')

# if I just want to make sure some words are not flagged as misspelled
spell.word_frequency.load_words(['microsoft', 'apple', 'google'])
spell.known(['microsoft', 'google'])  # will return both now!

If the words that you wish to check are long, it is recommended to reduce the distance to 1. This can be accomplished either when initializing the spell check class or after the fact.

from spellchecker import SpellChecker

spell = SpellChecker(distance=1)  # set at initialization

# do some work on longer words

spell.distance = 2  # set the distance parameter back to the default

Additional Methods

On-line documentation is available; below contains the cliff-notes version of some of the available functions:

correction(word): Returns the most probable result for the misspelled word

candidates(word): Returns a set of possible candidates for the misspelled word

known([words]): Returns those words that are in the word frequency list

unknown([words]): Returns those words that are not in the frequency list

word_probability(word): The frequency of the given word out of all words in the frequency list

The following are less likely to be needed by the user but are available:

edit_distance_1(word): Returns a set of all strings at a Levenshtein Distance of one based on the alphabet of the selected language

edit_distance_2(word): Returns a set of all strings at a Levenshtein Distance of two based on the alphabet of the selected language

Credits

Metadata

Release files for pyspellchecker 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyspellchecker 0.5.2
File Size Uploaded Provenance Actions
pyspellchecker-0.5.2.tar.gz 1.9 MB Without provenance Details for pyspellchecker-0.5.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyspellchecker 0.5.2
File Interpreter ABI Platform Actions
pyspellchecker-0.5.2-py2.py3-none-any.whl Python 2, Python 3 none any Details for pyspellchecker-0.5.2-py2.py3-none-any.whl

Total release size: 3.8 MB

Release files / pyspellchecker-0.5.2.tar.gz

Download URL pyspellchecker-0.5.2.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
bdf564fbeeb4ae456bffa6557c08199c7048fb103553dbaa8ffe36b248d9b5c1
BLAKE2b-256 checksum
How to use checksums
528dbea3da2e2cc8f27ca1e1b8d5e174c17dd06ef4994b27246879668b5933eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

Release files / pyspellchecker-0.5.2-py2.py3-none-any.whl

Download URL pyspellchecker-0.5.2-py2.py3-none-any.whl
Size 1.9 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6ff9d7cd4da76c8f112b83e46bd2a19c2a6aa9300266af927b98b8eb7dc95fdd
BLAKE2b-256 checksum
How to use checksums
3b62e9da86d71e3ccc500b979f0afb88c1f3ae151766004a0de92775b686a311
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.2

Security for pyspellchecker 0.5.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.2 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