Registry / ai-ml / fasttext-langdetect

fasttext-langdetect

JSON →
library1.1.1pypypi✓ verified 86d ago

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.

pip install fasttext-langdetect
INSTALL
IMPORT
SIG · FASTTEXT-LANGDETEC
F
fasttext-langdetect
ai-mlpythonv1.1.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
2/4 runs
2/4 runs
py 3.11
2/4 runs
2/4 runs
py 3.12
2/4 runs
2/4 runs
py 3.13
2/4 runs
2/4 runs
py 3.9
2/4 runs
2/4 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

detect
from ftlangdetect import detect

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}")
Debug
Known issues
gotchaThe FastText language model files are downloaded on the first call to the `detect()` function. This requires an active internet connection and sufficient disk space (the full model is ~126MB, the low-memory version is ~917KB). Subsequent calls will use the cached models.
fix
Ensure network connectivity and appropriate disk space for the initial model download. The model typically caches in a temporary system directory.
affects: All versions
gotchaThe `low_memory` parameter (defaulting to `False`) controls which model is used. Setting `low_memory=True` loads a compressed model that uses less memory but may result in slightly lower detection accuracy compared to the full model (`low_memory=False`).
fix
Choose `low_memory=True` for memory-constrained environments at the cost of slight accuracy, or `low_memory=False` (default) for maximum accuracy.
affects: All versions
gotchaLanguage detection accuracy can be reduced for very short text inputs (e.g., single words, short phrases) or extremely long inputs. FastText models are generally optimized for text segments around 10-80 characters for optimal performance.
fix
For short texts, results may be less reliable. Consider providing more context if possible. For very long texts, breaking them into smaller, meaningful segments might improve accuracy.
affects: All versions
gotchaPre-trained FastText models are often trained on clean, well-structured text. Noisy inputs (e.g., text with spelling errors, unusual capitalization, slang, or mixed languages/code-switching) can lead to reduced detection accuracy.
fix
Consider pre-processing input text (e.g., lowercasing, basic cleaning) if dealing with informal or noisy user-generated content to potentially improve results.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ftlangdetect'
The 'fasttext-langdetect' Python package is either not installed in your environment or there's a typo in the import statement.
fix
Ensure the package is installed using `pip install fasttext-langdetect` and use the correct import: `from ftlangdetect import detect`.
ValueError: Invalid model file.
The FastText language identification model file is corrupted, incomplete, or the path provided for a custom model is incorrect, leading to a failure during model loading.
fix
Ensure a stable internet connection during the first use for automatic model download, or if using a custom model, verify its integrity and the correctness of the file path. Clearing the library's cache directory (usually in a system temp location or specified by FTLANG_CACHE) can resolve issues with corrupted auto-downloaded models.
MemoryError
Your system does not have sufficient available RAM to load the FastText language detection model, especially the larger 'full' model.
fix
When calling `detect()`, explicitly use the `model='lite'` option to load a smaller, less memory-intensive model (e.g., `detect(text='...', model='lite')`). Alternatively, use `model='auto'`, which attempts to fall back to the lite model if loading the full model causes a MemoryError. Ensure your system has adequate RAM if you require the 'full' model.
AttributeError: module 'fast_langdetect' has no attribute 'ft_detect'
The function name 'ft_detect' is not part of the public API for the `fasttext-langdetect` library (which uses `ftlangdetect` as its import name). The primary function for language detection is `detect`.
fix
Import the `detect` function directly using `from ftlangdetect import detect` and then call it as `detect(text='your text here')`.
Upgrade
Version history
1.1.1latest on PyPI · released May 26, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
fasttext-langdetect — pip install fasttext-langdetect · libregistry