Registry / ai-ml / lingua-language-detector

lingua-language-detector

JSON →
library2.2.0pypypi✓ verified 23d ago

Lingua Language Detector is an accurate natural language detection library for Python, suitable for both short text snippets and mixed-language texts. It leverages Rust bindings for high performance and low memory consumption, supporting 75 languages offline. The current version is 2.2.0, with an active development cycle featuring regular minor and patch releases.

pip install lingua-language-detector
INSTALL
IMPORT
SIG · LINGUA-LANGUAGE-DE
L
lingua-language-detector
ai-mlpythonv2.2.0
Install
3.6s avg
Import
Disk
187MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 113.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.000s · 114MB
187MB installed
● package 187MB
Code
Verified usage

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

Language
from lingua import Language
LanguageDetectorBuilder
from lingua import LanguageDetectorBuilder

This quickstart demonstrates how to build a language detector, detect the language of a single text, and identify multiple languages within a mixed-language text. It utilizes the `Language` enum and `LanguageDetectorBuilder` to configure and create a detector instance.

from lingua import Language, LanguageDetectorBuilder # Build a detector for specific languages languages = [Language.ENGLISH, Language.FRENCH, Language.GERMAN] detector = LanguageDetectorBuilder.from_languages(*languages).build() # Detect a single language text_single = "languages are awesome" detected_language_single = detector.detect_language_of(text_single) print(f"Detected language (single): {detected_language_single.name}") # Detect multiple languages in mixed text (experimental) text_mixed = "Hello world, comment ça va? Das ist ein Test." detected_languages_mixed = detector.detect_multiple_languages_of(text_mixed) print("Detected languages (mixed):") for result in detected_languages_mixed: print(f" - {result.language.name}: '{text_mixed[result.start_index:result.end_index]}' ({result.start_index}-{result.end_index})")
Debug
Known issues
breakingVersion 2.0.0 completely replaced the pure Python implementation with Rust bindings, changing the underlying API. Code written for `1.x` versions will likely break and require adaptation.
fix
Review the official documentation for `lingua-language-detector` 2.x and update code to use the new API, especially `LanguageDetectorBuilder` and `Language` enum.
affects: >=2.0.0
breakingStarting with version 2.1.1, support for Python 3.10 and 3.11 was dropped. The library now requires Python 3.12 or newer.
fix
Upgrade your Python environment to version 3.12 or higher.
affects: >=2.1.1
gotchaUsing `LanguageDetectorBuilder.with_low_accuracy_mode()` improves performance and reduces memory but significantly decreases detection accuracy for texts shorter than 120 characters.
fix
Avoid `with_low_accuracy_mode()` for short texts or applications where high accuracy is paramount. Consider pre-filtering languages to optimize performance without sacrificing accuracy.
affects: >=1.5.0
gotchaThe `detect_multiple_languages_of()` method for mixed-language texts is considered experimental. Its results are highly dependent on the input text and it performs best in high-accuracy mode with longer words.
fix
Be aware of potential inaccuracies when using `detect_multiple_languages_of()` on very short or ambiguous mixed texts. Test thoroughly with your specific data.
affects: >=1.5.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lingua'
The 'lingua' module is not installed or not found in the Python environment.
fix
Install the module using 'pip install lingua-language-detector'.
ImportError: cannot import name 'LanguageDetector' from 'lingua'
The 'LanguageDetector' class does not exist in the 'lingua' module.
fix
Use 'from lingua import LanguageDetectorBuilder' instead.
TypeError: 'LanguageDetectorBuilder' object is not callable
Attempting to call 'LanguageDetectorBuilder' directly instead of using its methods.
fix
Use 'LanguageDetectorBuilder.from_languages(*languages).build()' to create a detector.
AttributeError: module 'lingua' has no attribute 'detect_language'
The 'detect_language' function does not exist in the 'lingua' module.
fix
Use 'detector.detect_language_of(text)' after building the detector.
ValueError: No languages specified for detection
No languages were provided when building the language detector.
fix
Specify languages using 'LanguageDetectorBuilder.from_languages(Language.ENGLISH, Language.FRENCH, ...).build()'.
Upgrade
Version history
2.2.0latest on PyPI · released Mar 9, 2026
Audit
Dependencies
pythonrequiredRequires Python >= 3.12
Agent activity
59 hits · last 30 days
node
56
Perplexity
1
Resources
lingua-language-detector — pip install lingua-language-detector · libregistry