Python bindings for the Rust fuzzy-aho-corasick crate.
Project description
fuzzy-aho-corasick
Python bindings for the Rust fuzzy-aho-corasick crate using PyO3 and maturin.
The wrapper currently exposes the upstream crate's main global builder options and a Python-side Pattern type for per-pattern configuration:
- Build a fuzzy matcher from a list of patterns
- Configure per-pattern weights
- Configure per-pattern custom unique IDs
- Configure per-pattern fuzzy limits
- Configure global edit limits
- Configure global penalty weights
- Run non-overlapping and overlapping fuzzy search, split, and text segmentation helpers
- Build a fuzzy replacer from
(pattern, replacement)pairs - Ship
py.typedmetadata and.pyistubs for editor type hints
Python API
from fuzzy_aho_corasick import FuzzyMatcher, FuzzyReplacer, Pattern
matcher = FuzzyMatcher(
[
Pattern("hello", edits=1, weight=1.5, custom_unique_id=7),
Pattern("world", substitutions=1),
],
case_insensitive=True,
)
matches = matcher.search("H3llo W0rld!", threshold=0.7)
for match in matches:
print(match.pattern, match.text, match.similarity, match.pattern_custom_unique_id)
overlap_matcher = FuzzyMatcher(["saddam", "ddamhu"], edits=1)
overlapping = overlap_matcher.search_overlapping("saddamddamhu", threshold=0.5)
assert len(overlapping) > len(overlap_matcher.search("saddamddamhu", threshold=0.5))
split_matcher = FuzzyMatcher(
["FOO", "BAR"],
edits=1,
case_insensitive=True,
)
assert matcher.search("H3llo W0rld!", threshold=0.7)[0].pattern == "hello"
assert split_matcher.split("xxFo0yyBAARzz", threshold=0.8) == ["xx", "yy", "zz"]
assert matcher.pattern_specs[0].custom_unique_id == 7
replacer = FuzzyReplacer(
[
(Pattern("foo", substitutions=1), "bar"),
(Pattern("baz", custom_unique_id=2), "qux"),
],
case_insensitive=True,
)
assert replacer.replace("fo0 and BAZ!", threshold=0.7) == "bar and qux!"
matcher.save("matcher.json")
loaded = FuzzyMatcher.load("matcher.json")
assert loaded.search("H3llo W0rld!", threshold=0.7)[0].pattern == "hello"
Search Modes
FuzzyMatcher.search() keeps the existing default behavior and returns non-overlapping matches unless you ask for a different strategy.
matches = matcher.search("H3llo W0rld!", threshold=0.7)
When you want overlapping matches, use the dedicated method instead of passing a string strategy:
overlapping = matcher.search_overlapping("saddamddamhu", threshold=0.5)
Overlap mode returns the full sorted upstream search result set. That means you can see additional nearby fuzzy candidates for the same pattern when they pass the threshold, not just one match per pattern.
For advanced control, search() still accepts these typed strategies:
"search": sorted matches with overlaps preserved"non_overlapping": sorted matches with overlaps removed"non_overlapping_unique": non-overlapping matches with one result per pattern or custom unique ID
The package now ships .pyi stubs together with py.typed, so editors such as Pylance can show method signatures, accepted strategy values, and return types.
Saving And Loading
FuzzyMatcher can persist its configuration to JSON with save() / load() or to_json() / from_json().
from fuzzy_aho_corasick import FuzzyMatcher, Pattern
matcher = FuzzyMatcher(
[Pattern("invoice", edits=1), Pattern("receipt", custom_unique_id=9)],
case_insensitive=True,
edits=2,
)
matcher.save("matcher.json")
loaded = FuzzyMatcher.load("matcher.json")
The saved form captures the matcher configuration and recreates the Rust engine when loaded. The upstream Rust crate does not currently expose a stable serialized form for the built automaton itself.
Local development
-
Install Rust using
rustup. -
Install maturin:
py -m pip install --upgrade maturin. -
Build and install the extension into your active environment:
maturin develop
-
Run tests:
pytest
Build distributions
Build wheels and an sdist locally:
maturin build --release
maturin sdist
Artifacts will land under target/wheels/ or the --out directory if you set one.
Publish to PyPI
Manual publish
maturin publish --release
GitHub Actions publish
This repository includes a workflow at .github/workflows/release.yml that:
- builds wheels on Linux, macOS, and Windows
- builds a source distribution
- uploads them to PyPI on tag pushes like
v0.1.0 - skips files that were already uploaded if the same workflow is rerun for the same tag
Recommended setup:
- Create the project on PyPI.
- Enable trusted publishing for your GitHub repository on PyPI.
- Replace the placeholder GitHub URLs in
pyproject.toml. - Push a version tag such as
v0.1.0.
PyPI does not allow reusing the same filename for a different upload. If 0.1.0 has already been published, make the next real release a new version such as 0.1.1. The workflow only skips already-existing files so reruns do not fail after a partial publish.
Notes
- The Python wrapper is intentionally small and focused on the upstream crate's core operations.
- Before publishing, update the author and project URLs in
pyproject.toml.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fuzzy_aho_corasick_rs-0.1.4.tar.gz.
File metadata
- Download URL: fuzzy_aho_corasick_rs-0.1.4.tar.gz
- Upload date:
- Size: 2.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0caef456d1fbf2cb00607db55c349a3701e2d1fd053fe13b15f40be4eb312165
|
|
| MD5 |
fbcf9f26878053d9c5c0c7762a73f21d
|
|
| BLAKE2b-256 |
6153742e53a55604354616353b145065c9a707d7e98d36b9a190bffb90413f35
|
Provenance
The following attestation bundles were made for fuzzy_aho_corasick_rs-0.1.4.tar.gz:
Publisher:
release.yml on vineel7871/fuzzy-aho-corasick-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuzzy_aho_corasick_rs-0.1.4.tar.gz -
Subject digest:
0caef456d1fbf2cb00607db55c349a3701e2d1fd053fe13b15f40be4eb312165 - Sigstore transparency entry: 1457551335
- Sigstore integration time:
-
Permalink:
vineel7871/fuzzy-aho-corasick-rs@0fb6d245f1cc413e68c337bff714b7195474d546 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/vineel7871
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0fb6d245f1cc413e68c337bff714b7195474d546 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 317.9 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db7c639ff0f521a077f0f84d55d068528093ae87404e04c125b6086648468cc8
|
|
| MD5 |
b4d118758dd1586d661b567558435db6
|
|
| BLAKE2b-256 |
ad497894808508df101158b91c898ba67e6c7a653e30b16f408da0fe50b6adc3
|
Provenance
The following attestation bundles were made for fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on vineel7871/fuzzy-aho-corasick-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-win_amd64.whl -
Subject digest:
db7c639ff0f521a077f0f84d55d068528093ae87404e04c125b6086648468cc8 - Sigstore transparency entry: 1457551456
- Sigstore integration time:
-
Permalink:
vineel7871/fuzzy-aho-corasick-rs@0fb6d245f1cc413e68c337bff714b7195474d546 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/vineel7871
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0fb6d245f1cc413e68c337bff714b7195474d546 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 470.7 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfc4fd811f30f11c567255a1602a918e616f5529956db6e3f6b3e8fdd10f67f4
|
|
| MD5 |
60091768f39ad65f54d5c9dbde08e6a8
|
|
| BLAKE2b-256 |
a631d190597ee8555524fb0281457e5ab17510320257c25a434e160bc12536f5
|
Provenance
The following attestation bundles were made for fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on vineel7871/fuzzy-aho-corasick-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
dfc4fd811f30f11c567255a1602a918e616f5529956db6e3f6b3e8fdd10f67f4 - Sigstore transparency entry: 1457551975
- Sigstore integration time:
-
Permalink:
vineel7871/fuzzy-aho-corasick-rs@0fb6d245f1cc413e68c337bff714b7195474d546 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/vineel7871
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0fb6d245f1cc413e68c337bff714b7195474d546 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 433.0 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aae32c6fdeb8edbd82217696dcdc441da66b1b7596cf1102485d1e8e3ee979fb
|
|
| MD5 |
cfc5f79c335c70de4025a68f7e97939e
|
|
| BLAKE2b-256 |
059180ed2d4a35eb0ae99000da021df221a37660b3c9347f292000b81d57bfcc
|
Provenance
The following attestation bundles were made for fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on vineel7871/fuzzy-aho-corasick-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuzzy_aho_corasick_rs-0.1.4-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
aae32c6fdeb8edbd82217696dcdc441da66b1b7596cf1102485d1e8e3ee979fb - Sigstore transparency entry: 1457552245
- Sigstore integration time:
-
Permalink:
vineel7871/fuzzy-aho-corasick-rs@0fb6d245f1cc413e68c337bff714b7195474d546 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/vineel7871
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0fb6d245f1cc413e68c337bff714b7195474d546 -
Trigger Event:
push
-
Statement type: