Fast Language Detection

1.0.0 · active · verified Sat Apr 11

fast-langdetect is an ultra-fast and highly accurate language detection library based on FastText, a library developed by Facebook. It offers 80x faster performance and up to 95% accuracy compared to conventional methods. The library supports Python versions 3.9 to 3.13 and works offline with a lightweight model, with continuous active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `fast-langdetect` to detect the language of various text inputs. It shows usage of the default 'lite' model, explicitly selecting the 'full' model for higher accuracy, and using the 'auto' model with fallback behavior.

from fast_langdetect import detect_language

text1 = "Hello, how are you?"
text2 = "Bonjour, comment allez-vous?"
text3 = "Este es un texto muy largo en español, con muchas palabras y frases para probar la detección de idioma."

# Detect language with default settings (lite model)
result1 = detect_language(text1)
print(f"'{text1}' detected as: {result1.lang} (confidence: {result1.score:.2f})")

# Detect language using the 'full' model for potentially higher accuracy
result2 = detect_language(text2, model='full')
print(f"'{text2}' detected as: {result2.lang} (confidence: {result2.score:.2f})")

# Detect language with 'auto' model, which falls back to lite on MemoryError
# Also request top 2 languages
result3 = detect_language(text3, model='auto', k=2)
print(f"'{text3}' detected top 2 as: {result3}")

view raw JSON →