Skip to main content

A Rust BK-tree implementation for fast fuzzy string matching in Python

Project description

fastbktree :deciduous_tree:

A Rust implementation of BK-trees for fast fuzzy string matching in Python.

Installation

uv add fastbktree
# pip install fastbktree

Quickstart

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.

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.

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

len(tree) -> int

Returns the number of strings in the tree.

size = len(tree)

levenshtein_distance(a: str, b: str) -> int

Pure Rust implementation of Levenshtein distance between two strings.

from fastbktree import levenshtein_distance

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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastbktree-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastbktree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (233.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file fastbktree-0.1.0.tar.gz.

File metadata

  • Download URL: fastbktree-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.7

File hashes

Hashes for fastbktree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1627c83b390b82270270acdaf93004064d2ada32fd5a244f62603a9e29a2511b
MD5 4c8061444ba7db9614e170fe11607b8f
BLAKE2b-256 8aa3a0aa20422142e1e79d597222c50786eea9e1eaeeb1b07bd725909306077c

See more details on using hashes here.

File details

Details for the file fastbktree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastbktree-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b66babbb5a8ef505e6c337f7462d867a21b0df88ce22fa782d9a10834983b51
MD5 2af8260f524663752b72728e370eb8b5
BLAKE2b-256 abaaffd99eef1d5f80f5a17f3c58719d79dc1305b118037ace3451440f55817b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page