Skip to main content

Pytypos

PyPI version Downloads PyPI - Downloads Code style: blue License contributions welcome

Description

Pytypos is a typo and spelling checker used to identify spelling mistakes in comments of a various programming languages, such as Python, Java, C++, C#, Matlab, and others. In addition, it can check other text-oriented files such as MD, RST, TXT, or similar.

Spell checking uses dictionaries installed on the host computer. The dictionary language can be defined in the Pytypos object with dictionary='de' for German, for instance. For installation and management of dictionaries, see the documentation of pyenchant. To list available dictionary languages on the host system, print pytypos.available_languages().

Installation

The easiest way to install is using pip:

pip install pytypos

To install from source:

git clone https://github.com/PApostol/pytypos.git
cd pytypos
python setup.py install

For usage details check help(pytypos).

Usage Examples

The below will recursively scan my/path/project/ for comments (i.e. # this is a comment) in Python files:

from pytypos import Pytypos
prj = Pytypos(target='my/path/project/', match_identifier='#', file_extension='py', recursive=True, suggestions=False)
prj.find_typos()
print(prj.typo_list)
print(prj.typo_details)

Pytypos.typo_list stores a list of all possible typos found.

Pytypos.typo_details stores a dictionary with the following structure:

If suggestions == False (default):

{'file1': ['typo1', 'typo2'],
 'file2': ['typo1', 'typo2']
}

If suggestions == True:

{'file1': [{'typo1': ['suggestion1a', 'suggestion1b'],
            'typo2': ['suggestion2a', 'suggestion2b']
           },
 'file2': [{'typo1': ['suggestion1a', 'suggestion1b'],
            'typo2': ['suggestion2a', 'suggestion2b']
           }
}

The above can be nicely printed on stdout with Python's built-in pprint.

Other Examples

# recursively scan "foo/bar/" for any text in RST files and give suggestions, but skip file "foo/UPDATE.rst" and exclude the words "repos" and "GitHub"
Pytypos(target='foo/bar/', match_identifier='', file_extension='rst', recursive=True, suggestions=True, exclude_file_list=['foo/UPDATE.rst'], exclude_word_list=['repos', 'GitHub'])

# scan the "a/b/c.java" Java file for comments (i.e. "// this is a comment") and give suggestions with a french dictionary, but exclude words found in "exclusions.txt"
Pytypos(target='a/b/c.java', match_identifier='//', dictionary='fr', suggestions=True, exclude_word_file='exclusions.txt')

Testing

You can do some simple testing after cloning the repo.

Note any additional requirements for running the tests: pip install -r tests/requirements.txt

python tests/run_integration_test.py

Additional methods

pytypos.Pytypos.fix_typos(): Fixes typos found in-between spaces with the most likely replacement

pytypos.Pytypos.add_to_dictionary(): Adds custom word list to dictionary

pytypos.Pytypos.add_to_exclusions(): Removes custom word list from dictionary

pytypos.Pytypos.replace_word(): Replaces words in dictionary

License

Released under MIT by @PApostol

  • You can freely modify and reuse.
  • The original license must be included with copies of this software.
  • Please link back to this repo if you use a significant portion the source code.

Metadata

Release files for pytypos 1.4.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 pytypos 1.4.0
File Size Uploaded Provenance Actions
pytypos-1.4.0.tar.gz 7.7 kB Without provenance Details for pytypos-1.4.0.tar.gz

Release files / pytypos-1.4.0.tar.gz

Download URL pytypos-1.4.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e34bd070c0517597c7c223fc976dc9978747d9de869e535c6a4ca122ed418b7b
BLAKE2b-256 checksum
How to use checksums
35580f60e55e788dfe8da71387cdc5bce8fd85b4fbf839e07d50ec04fe159a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for pytypos 1.4.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.

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

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