--- id: ngram version: "4.0.3" license: LGPL3 license_treatment: copyleft maintenance: abandoned --- # ngram — A `set` subclass providing fuzzy search based on N-grams. License: copyleft · Maintenance: abandoned · Downloads: 180.8K/mo ## 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 above — 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 pip install ngram uv add ngram 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_current - Install friction: low - Maintenance: abandoned - Downloads: 180.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags fuzzy string matching, n-gram similarity search, approximate string matching, string similarity set, typo-tolerant search, character n-gram indexing, fuzzy search library, fuzzy-matching, string-similarity, abandoned [View on SkillFed](https://skillfed.io/packages/ngram) · [View on PyPI](https://pypi.org/project/ngram/)