{"id":6900,"library":"strsimpy","title":"String Similarity and Distance Measures","description":"Strsimpy is a Python library that provides implementations for various string similarity and distance measures, including popular algorithms like Levenshtein, Jaro-Winkler, N-Gram, Cosine Similarity, and Jaccard Index. It's designed to be straightforward to use for text analysis and data matching tasks. The current version is 0.2.1. Releases are infrequent, typically addressing bug fixes or adding new algorithms.","status":"active","version":"0.2.1","language":"python","source_language":"en","source_url":"https://github.com/luozhouyang/python-string-similarity","tags":["string-similarity","levenshtein","jaro-winkler","text-analysis","nlp","data-matching"],"install":[{"cmd":"pip install strsimpy","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Levenshtein","correct":"from strsimpy.levenshtein import Levenshtein"},{"symbol":"JaroWinkler","correct":"from strsimpy.jaro_winkler import JaroWinkler"},{"symbol":"Ngram","correct":"from strsimpy.ngram import Ngram"},{"wrong":"from strsimpy.weighted_levenshtein import Levenshtein","symbol":"WeightedLevenshtein","correct":"from strsimpy.weighted_levenshtein import WeightedLevenshtein"}],"quickstart":{"code":"from strsimpy.levenshtein import Levenshtein\n\ns0 = \"안녕하세요\"\ns1 = \"안녕하세유\"\n\nlevenshtein = Levenshtein()\ndistance = levenshtein.distance(s0, s1)\nprint(f\"Levenshtein distance between '{s0}' and '{s1}': {distance}\")\n\ns2 = \"apple\"\ns3 = \"aple\"\ndistance2 = levenshtein.distance(s2, s3)\nprint(f\"Levenshtein distance between '{s2}' and '{s3}': {distance2}\")\n\nfrom strsimpy.jaro_winkler import JaroWinkler\n\njaro_winkler = JaroWinkler()\nsimilarity = jaro_winkler.similarity(s2, s3)\nprint(f\"Jaro-Winkler similarity between '{s2}' and '{s3}': {similarity}\")","lang":"python","description":"This quickstart demonstrates calculating Levenshtein distance and Jaro-Winkler similarity between strings. Most algorithms follow a pattern of instantiating a class and then calling a `distance()` or `similarity()` method."},"warnings":[{"fix":"Update all `import similarity...` statements to `import strsimpy...` and reinstall the package.","message":"The package name was changed from `similarity` to `strsimpy`. Old import paths will fail.","severity":"breaking","affected_versions":"<0.1.2"},{"fix":"Review the documentation for `WeightedLevenshtein` and update your weight calculation logic to use direct functions as arguments, rather than class instances.","message":"The `WeightedLevenshtein` algorithm's API changed significantly in v0.1.7. It now uses functions for weight calculation instead of expecting Class or Objects, simplifying its usage.","severity":"breaking","affected_versions":"<0.1.7"},{"fix":"If your project requires `numpy`, ensure it is explicitly listed in your project's dependencies.","message":"The `numpy` dependency was removed in v0.1.5 to lighten the package. If you were implicitly relying on `numpy` being installed alongside `strsimpy`, it might no longer be present.","severity":"gotcha","affected_versions":"<0.1.5"},{"fix":"Upgrade to version 0.1.2 or later to ensure correct calculations and avoid potential runtime errors with ShingleBased algorithms.","message":"A `ZeroDivisionError` was fixed in ShingleBased algorithms (e.g., Jaccard, Cosine Similarity) for certain edge cases.","severity":"gotcha","affected_versions":"<0.1.2"}],"env_vars":null,"search_vec":"'0.2.1':56 'ad':65 'address':61 'algorithm':23,67 'analysi':47,77 'bug':62 'cosin':32 'current':53 'data':49,80 'data-match':79 'design':39 'distanc':4,19 'fix':63 'gram':31 'implement':13 'includ':21 'index':36 'infrequ':59 'jaccard':35 'jaro':27,73 'jaro-winkl':26,72 'levenshtein':25,71 'librari':10 'like':24 'match':50,81 'measur':5,20 'n':30 'n-gram':29 'new':66 'nlp':78 'popular':22 'provid':12 'python':9 'releas':57 'similar':2,17,33,70 'straightforward':42 'string':1,16,69 'string-similar':68 'strsimpi':6 'task':51 'text':46,76 'text-analysi':75 'typic':60 'use':44 'various':15 'version':54 'winkler':28,74","created_at":"2026-04-15T18:47:51.345257+00:00","updated_at":"2026-04-16T22:29:37.571972+00:00","problems":[{"fix":"from strsimpy.similarity.jarowinkler import JaroWinkler","cause":"String similarity algorithms like JaroWinkler are not directly exposed at the top level of the `strsimpy` module; they reside in their specific submodules within `strsimpy.similarity`.","error":"ModuleNotFoundError: No module named 'strsimpy.JaroWinkler'"},{"fix":"from strsimpy.similarity.jarowinkler import JaroWinkler\njarowinkler_sim = JaroWinkler()","cause":"The `JaroWinkler` class is not a direct attribute of the top-level `strsimpy` module. It must be imported from its specific submodule.","error":"AttributeError: module 'strsimpy' has no attribute 'JaroWinkler'"},{"fix":"s1 = str(s1) if s1 is not None else ''\ns2 = str(s2) if s2 is not None else ''\nsimilarity_score = your_similarity_object.similarity(s1, s2)","cause":"One or both of the input arguments passed to a similarity method (e.g., `similarity(s1, s2)`) are not strings, leading to string operations failing.","error":"TypeError: object of type 'NoneType' has no len()"},{"fix":"from strsimpy.similarity.ngram import NGram\nngram_sim = NGram(n=2) # Specify 'n' for bigrams, trigrams, etc.","cause":"When initializing an `NGram` similarity object, the required `n` parameter, which defines the size of the n-grams, was not provided.","error":"TypeError: __init__() missing 1 required positional argument: 'n'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.2.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/luozhouyang/python-string-similarity","docs":null,"changelog":null,"pypi":"https://pypi.org/project/strsimpy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}