Backend discovery and safe fallback#
Inspect backend capability without making optional accelerators mandatory.
internal available=True license=MIT
rapidfuzz available=False license=MIT
levenshtein available=False license=GPL-2.0-or-later
python available=True license=BSD-3-Clause
auto selected: internal
from scikitplot.levenshtein import available_backends, backend_info, distance
for info in available_backends():
print(
f"{info.name:11s} available={str(info.available):5s} "
f"license={info.license}"
)
auto = backend_info("auto")
assert auto.available
# This path always exists, even in a minimal installation.
assert distance("kitten", "sitting", backend="python") == 3
# The GPL backend is visible to explicit capability discovery but is not part
# of the automatic preference chain.
names = [item.name for item in available_backends()]
assert names == ["internal", "rapidfuzz", "levenshtein", "python"]
print("auto selected:", auto.name)
Total running time of the script: (0 minutes 0.007 seconds)
Related examples