Metadata-Version: 2.4
Name: fuzzy-aho-corasick-rs
Version: 0.1.0
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Linguistic
Requires-Dist: maturin>=1.7,<2.0 ; extra == 'dev'
Requires-Dist: pytest>=8.0 ; extra == 'dev'
Provides-Extra: dev
Summary: Python bindings for the Rust fuzzy-aho-corasick crate.
Keywords: aho-corasick,fuzzy,string-matching,rust,pyo3
Home-Page: https://github.com/vineel7871/fuzzy-aho-corasick-rs
Author: Vineel K
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/vineel7871/fuzzy-aho-corasick-rs
Project-URL: Issues, https://github.com/vineel7871/fuzzy-aho-corasick-rs/issues
Project-URL: Repository, https://github.com/vineel7871/fuzzy-aho-corasick-rs

# fuzzy-aho-corasick

Python bindings for the Rust [`fuzzy-aho-corasick`](https://crates.io/crates/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 fuzzy search, split, and text segmentation helpers
- Build a fuzzy replacer from `(pattern, replacement)` pairs

## Python API

```python
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)

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!"
```

## Local development

1. Install Rust using `rustup`.
2. Install maturin: `py -m pip install --upgrade maturin`.
3. Build and install the extension into your active environment:

   ```powershell
   maturin develop
   ```

4. Run tests:

   ```powershell
   pytest
   ```

## Build distributions

Build wheels and an sdist locally:

```powershell
maturin build --release
maturin sdist
```

Artifacts will land under `target/wheels/` or the `--out` directory if you set one.

## Publish to PyPI

### Manual publish

```powershell
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`

Recommended setup:

1. Create the project on PyPI.
2. Enable trusted publishing for your GitHub repository on PyPI.
3. Replace the placeholder GitHub URLs in `pyproject.toml`.
4. Push a version tag such as `v0.1.0`.

## 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`.

