Detects language of given text. Returns detected language codes and scores.
Before using Detect Language API client you have to setup your personal API key. You can get it by signing up at https://detectlanguage.com
pip install detectlanguage
When upgrading please check changelog for breaking changes.
import detectlanguage
detectlanguage.configuration.api_key = "YOUR API KEY"
# You can use proxy if needed
# detectlanguage.configuration.proxies = {'https': 'https://user:pass@proxy:8080'}
detectlanguage.detect("Dolce far niente")
[{'language': 'it', 'score': 0.5074}]
If you need just a language code you can use detect_code
.
detectlanguage.detect_code("Dolce far niente")
'it'
It is possible to detect language of several texts with one request. This method is faster than doing one request per text.
detectlanguage.detect_batch(["Dolce far niente", "Hello world"])
Result is array of detections in the same order as the texts were passed.
[[{'language': 'it', 'score': 0.5074}], [{'language': 'en', 'score': 0.9098}]]
detectlanguage.account_status()
{ 'status': 'ACTIVE', 'daily_requests_limit': 5000, 'daily_bytes_limit': 1048576,
'bytes': 3151, 'plan': 'FREE', 'date': '2014-03-29', 'requests': 263,
'plan_expires': None }
detectlanguage.languages()
[{'code': 'aa', 'name': 'Afar'}, {'code': 'ab', 'name': 'Abkhazian'}, ...]
Detect Language API Python Client is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.