skillfed

ngram

A `set` subclass providing fuzzy search based on N-grams.

ngram v4.0.3 180.8K downloads/30d#10,139 on PyPI118
Copyleft license LGPL3 Abandoned released

What it is and what it does

NGram is a Python set subclass that indexes items by their character-based N-gram representation (default N=3), enabling fuzzy search by string similarity. When you add items to an NGram set, it pads each item's string representation, splits it into overlapping N-character substrings, and stores associations between those N-grams and the items. To find similar items, you query with a string, and the class ranks results by the ratio of shared to unshared N-grams, returning matches even when the query doesn't exactly match any stored item.

The package is designed for non-string items too—you provide a key function (like `str`) to extract or normalize the string representation before indexing. It does not implement a language model; it is purely a character-level similarity index. The library has been in production use since 2007 but is no longer actively maintained, with the last release in 2021-09-15.

Use it for:

  • Implement a typo-tolerant search in a dataset where exact matches fail but similar strings should be found.
  • Build a duplicate-detection system that identifies near-duplicate strings by N-gram overlap.
  • Create a spell-checker or autocorrect feature that ranks candidate corrections by string similarity.
  • Index and search user-provided text where minor spelling variations are common.
  • Perform fuzzy matching between datasets to link records that refer to the same entity with slightly different names.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Extends Python's set class to perform fuzzy string matching using N-gram similarity, allowing efficient searches for similar items in a collection.

Yes, if you need lightweight fuzzy string matching in a standalone Python project and can accept that the package is no longer maintained. The library is stable, has no dependencies, and works with current Python versions. However, do not adopt it for security-sensitive applications or if you require ongoing maintenance and updates.

Install

ngram on PyPI

pip

pip install ngram

uv

uv add ngram

poetry

poetry add ngram

Installing ngram

Before you install

Low install friction with no runtime dependencies. However, the package is abandoned—last commit was 2021-09-15, over 1794 days ago. While marked Production/Stable and supporting current Python versions, no active maintenance means security or compatibility issues will not be addressed.

License in practice

Licensed under LGPLv3 (copyleft). You may use and modify the package freely, but any derivative work must also be released under a compatible copyleft license. Proprietary or closed-source projects should review copyleft obligations before adopting.

Quickstart

pip install ngram

from ngram import NGram

ng = NGram(items=['apple', 'application', 'apply'])
results = ng.search('aple')

Verify before relying

  • Whether the package handles Unicode or non-ASCII strings correctly in modern Python environments.
  • Performance characteristics on large datasets or with very long strings.
  • Compatibility with recent Python minor versions despite the 'supports_current' classification.

Package facts

License LGPL3 (copyleft)
Python support supports the current Python release (>=3.0)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance abandoned — 1,794 days since the last release
Last repo commit
First released
Downloads 180,831/month — #10,139 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: ngram-4.0.3-py3-none-any.whl

Keywords: ngram, set, string, text, similarity

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)Natural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Text ProcessingTopic :: Text Processing :: IndexingTopic :: Text Processing :: Linguistic

Tags

fuzzy string matchingn-gram similarity searchapproximate string matchingstring similarity settypo-tolerant searchcharacter n-gram indexingfuzzy search library
fuzzy-matchingstring-similarityabandoned

More Text Processing packages