FastText Language Detection

1.0.5 · maintenance · verified Wed Apr 15

fasttext-langdetect is a Python wrapper for Facebook's FastText language identification model. It offers fast and up to 95% accurate language detection across over 170 languages. The library, currently at version 1.0.5 (last released in January 2023), provides a straightforward interface for identifying the language of a given text string. It downloads the necessary FastText model on its first use.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `detect` function and use it to identify the language of a given text. It shows examples for both the full accuracy model (default) and the low-memory model.

from ftlangdetect import detect

# Detect language with default settings (low_memory=False for higher accuracy)
result_full = detect(text="Bugün hava çok güzel")
print(f"Full model result: {result_full}")

# Detect language with low_memory option (smaller model, slightly less accurate)
result_low_memory = detect(text="Bugün hava çok güzel", low_memory=True)
print(f"Low-memory model result: {result_low_memory}")

# Example with English text
english_text = "Hello, world! How are you?"
result_en = detect(text=english_text)
print(f"English text result: {result_en}")

view raw JSON →