{"id":47185592,"url":"https://github.com/shner-elmo/flashtext2","last_synced_at":"2026-03-13T09:08:28.266Z","repository":{"id":86591625,"uuid":"584023541","full_name":"shner-elmo/flashtext2","owner":"shner-elmo","description":"The fastest FlashText library for Python","archived":false,"fork":false,"pushed_at":"2024-07-04T14:35:32.000Z","size":1982,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-26T19:46:49.524Z","etag":null,"topics":["extracting-keywords","flashtext","flashtext2","nlp","pyo3","python","rust","string","text-processing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shner-elmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-01T00:41:27.000Z","updated_at":"2025-11-25T10:50:24.000Z","dependencies_parsed_at":"2023-10-15T18:03:01.641Z","dependency_job_id":"579e5643-60cd-49e5-bd24-4dd44aa6e7e4","html_url":"https://github.com/shner-elmo/flashtext2","commit_stats":null,"previous_names":["shner-elmo/flashtext2"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/shner-elmo/flashtext2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2Fflashtext2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2Fflashtext2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2Fflashtext2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2Fflashtext2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shner-elmo","download_url":"https://codeload.github.com/shner-elmo/flashtext2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shner-elmo%2Fflashtext2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30463671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T06:34:02.089Z","status":"ssl_error","status_checked_at":"2026-03-13T06:33:49.182Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extracting-keywords","flashtext","flashtext2","nlp","pyo3","python","rust","string","text-processing"],"created_at":"2026-03-13T09:08:27.112Z","updated_at":"2026-03-13T09:08:28.236Z","avatar_url":"https://github.com/shner-elmo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \n  \u003ca href=\"https://pypi.org/project/flashtext2\"\u003e![PyPi Version](https://badge.fury.io/py/flashtext2.svg)\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/flashtext2\"\u003e![Supported Python versions](https://img.shields.io/pypi/pyversions/flashtext2.svg?color=%2334D058)\u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/flashtext2\"\u003e![Downloads](https://static.pepy.tech/badge/flashtext2)\u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/flashtext2\"\u003e![Downloads](https://static.pepy.tech/badge/flashtext2/month)\u003c/a\u003e\n    \n\u003c/div\u003e\n\n```sh\npip install flashtext2\n```\n\n# flashtext2\n\n`flashtext2` is an optimized version of the `flashtext` library for fast keyword extraction and replacement. \nIts orders of magnitude faster compared to regular expressions.\n\n## Key Enhancements in flashtext2\n\n- **Rewritten for Better Performance**: Completely rewritten in Rust, making it approximately 3-10x faster than the original version.\n- **Unicode Standard Annex #29**: Instead of relying on arbitrary regex patterns like **flashtext** \n[does](https://github.com/vi3k6i5/flashtext/blob/b316c7e9e54b6b4d078462b302a83db85f884a94/flashtext/keyword.py#L13): `[A-Za-z0-9_]+`, \n**flashtext2** uses the [Unicode Standard Annex #29](https://www.unicode.org/reports/tr29/) to split strings into tokens. \nThis ensures compatibility with all languages, not just Latin-based ones.\n- **Unicode Case Folding**: Instead of converting strings to lowercase for case-insensitive matches, it uses \n[Unicode case folding](https://www.w3.org/TR/charmod-norm/#definitionCaseFolding), ensuring accurate normalization \nof characters according to the Unicode standard.\n- **Fully Type-Hinted API**: The entire API is fully type-hinted, providing better code clarity and improved development experience.\n\n\n## Usage\n\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to unfold usage\u003c/summary\u003e\n\n### Keyword Extraction\n\n```python\nfrom flashtext2 import KeywordProcessor\n\nkp = KeywordProcessor(case_sensitive=False)\n\nkp.add_keyword('Python')\nkp.add_keyword('flashtext')\nkp.add_keyword('program')\n\ntext = \"I love programming in Python and using the flashtext library.\"\n\nkeywords_found = kp.extract_keywords(text)\nprint(keywords_found)\n# Output: ['Python', 'flashtext']\n\nkeywords_found = kp.extract_keywords_with_span(text)\nprint(keywords_found)\n# Output: [('Python', 22, 28), ('flashtext', 43, 52)]\n```\n\n### Keyword Replacement\n\n```python\nfrom flashtext2 import KeywordProcessor\n\nkp = KeywordProcessor(case_sensitive=False)\n\nkp.add_keyword('Java', 'Python')\nkp.add_keyword('regex', 'flashtext')\n\ntext = \"I love programming in Java and using the regex library.\"\nnew_text = kp.replace_keywords(text)\n\nprint(new_text)\n# Output: \"I love programming in Python and using the flashtext library.\"\n```\n\n### Case Sensitivity\n\n```python\nfrom flashtext2 import KeywordProcessor\n\ntext = 'abc aBc ABC'\n\nkp = KeywordProcessor(case_sensitive=True)\nkp.add_keyword('aBc')\n\nprint(kp.extract_keywords(text))\n# Output: ['aBc']\n\nkp = KeywordProcessor(case_sensitive=False)\nkp.add_keyword('aBc')\n\nprint(kp.extract_keywords(text))\n# Output: ['aBc', 'aBc', 'aBc']\n```\n\n### Other Examples\n\nOverlapping keywords (returns the longest sequence)\n```python\nfrom flashtext2 import KeywordProcessor\n\nkp = KeywordProcessor(case_sensitive=True)\nkp.add_keyword('machine')\nkp.add_keyword('machine learning')\n\ntext = \"machine learning is a subset of artificial intelligence\"\nprint(kp.extract_keywords(text))\n# Output: ['machine learning']\n```\n\nCase folding\n```python\nfrom flashtext2 import KeywordProcessor\n\nkp = KeywordProcessor(case_sensitive=False)\nkp.add_keywords_from_iter([\"flour\", \"Maße\", \"ᾲ στο διάολο\"])\n\ntext = \"ﬂour, MASSE, ὰι στο διάολο\"\nprint(kp.extract_keywords(text))\n# Output: ['flour', 'Maße', 'ᾲ στο διάολο']\n```\n\u003c/details\u003e\n\n\n### Performance\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n  Click to unfold performance\n  \u003c/summary\u003e\n\nExtracting keywords is usually 2.5-3x faster, and replacing them is about 10x.  \nThere is still room to optimize the code and improve performance.   \nYou can find the benchmarks [here](https://github.com/shner-elmo/FlashText2.0/tree/master/benchmarks).\n\n\n![Image](benchmarks/extract-keywords.png)\n\n![Image](benchmarks/replace-keywords.png)\n\nThe words have on average 6 characters, and a sentence has 10k words, so the length is 60k.\n\u003c/details\u003e\n\n\n### TODO\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n  Click to unfold TODO\n  \u003c/summary\u003e\n\n* Add multiple ways of normalizing strings: simple case folding, full case folding, and locale-aware folding\n* Remove all clones in src code\n\u003c/details\u003e\n\nCredit to [Vikash Singh](https://github.com/vi3k6i5/), the author of the original `flashtext` package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshner-elmo%2Fflashtext2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshner-elmo%2Fflashtext2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshner-elmo%2Fflashtext2/lists"}