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.
pip install fast-langdetectVerified import paths — ran on the pinned version, not inferred.
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.
Migrate to using `LangDetectConfig` objects. For example, pass `config=LangDetectConfig(cache_dir='your/path')` to `LangDetector` or use `FTLANG_CACHE` environment variable before importing and initializing any components if not explicitly setting `cache_dir`.
For longer texts, disable truncation via `LangDetectConfig(max_input_length=None)` if you understand the potential performance or accuracy implications. For short texts, be aware of inherent accuracy limitations.
Explicitly choose `model='lite'` for memory-constrained environments, `model='full'` for highest accuracy, or `model='auto'` with awareness of its specific fallback condition.
Implement standard Python error handling (try-except blocks) for potential I/O or network issues when using the library.
Be aware that newline characters are processed this way. If exact text formatting is critical for other parts of your pipeline, perform necessary pre-processing before passing text to `fast-langdetect`.
If redistributing or modifying the model files, ensure compliance with the CC BY-SA 3.0 license terms, including attribution and share-alike conditions.
Rename your script to avoid conflicts, e.g., 'language_detection.py', and ensure the 'langdetect' module is installed and correctly imported.
Ensure the input text contains enough alphabetic characters to allow for accurate language detection.
Install the 'langdetect' module using pip: 'pip install langdetect'.
Use the public `detect` function directly, which is the primary entry point for language detection. For example: `from fast_langdetect import detect; detect('your text')`.Install the library using pip: `pip install fast-langdetect`.