Metadata-Version: 2.4
Name: fastbktree
Version: 0.1.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
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: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Text Processing :: General
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Summary: A Rust BK-tree implementation for fast fuzzy string matching in Python
Keywords: bktree,levenshtein,fuzzy-matching,string-matching,rust
Author-email: Amrit Rau <amritrau@users.noreply.github.com>
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# fastbktree :deciduous_tree:

A Rust implementation of [BK-trees](https://en.wikipedia.org/wiki/BK-tree) for fast fuzzy string matching in Python.


## Installation

```bash
uv add fastbktree
# pip install fastbktree
```

## Quickstart
```python
from fastbktree import BKTree

# Create a BK-tree from a list of strings
tree = BKTree(["hello", "help", "hell", "shell", "helper"])

# Search for similar strings within a maximum distance
results = tree.search("helo", max_distance=2)
# Returns: [("hello", 1), ("hell", 1), ("help", 1)]

# Get the size of the corpus
print(len(tree))  # 5
```

## Reference

### `BKTree(iterable)`
Creates a new BK-tree from an iterable of strings.

```python
tree = BKTree(["word1", "word2", "word3"])
```

### `tree.search(query: str, max_distance: int) -> List[Tuple[str, int]]`
Searches for strings similar to `query` within `max_distance` Levenshtein distance.
Returns a list of `(string, distance)` tuples.

```python
results = tree.search("query", max_distance=2)
```

### `len(tree) -> int`
Returns the number of strings in the tree.

```python
size = len(tree)
```

### `levenshtein_distance(a: str, b: str) -> int`
Pure Rust implementation of Levenshtein distance between two strings.

```python
from fastbktree import levenshtein_distance

distance = levenshtein_distance("kitten", "sitting")  # 3
```


## License
MIT

