Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

CFFI bindings around Google Chromium's embedded compact language detection library (CLD2)

Project Description

CFFI bindings for CLD2

This package contains the CLD (Compact Language Detection) library as maintained by Dick Sites ( The first fork was done at revision r161. It also contains python bindings that were originally created by Mike McCandless. The bindings have gone through several hands, with the latest changes being made to rework the bindings for CFFI.

These bindings are identical in API to the original cld2 bindings, and as a result can be used as a drop in replacement.

The LICENSE is the same as Chromium’s LICENSE and is included in the LICENSE file for reference.


Should be as simple as

$ pip install cld2-cffi

Development Version

The latest development version can be installed directly from GitHub:

$ pip install --upgrade 'git+'


import cld2

isReliable, textBytesFound, details = cld2.detect("This is my sample text")
print('  reliable: %s' % (isReliable != 0))
print('  textBytes: %s' % textBytesFound)
print('  details: %s' % str(details))

# The output looks like so:
#  reliable: True
#  textBytes: 24
#  details: (('ENGLISH', 'en', 95, 1736.0), ('Unknown', 'un', 0, 0.0), ('Unknown', 'un', 0, 0.0))


First, you must get your content (plain text or HTML) encoded into UTF8 bytes. Then, detect like this:

isReliable, textBytesFound, details = cld2.detect(bytes)
is True if the top language is much better than 2nd best language.
tells you how many actual bytes CLD analyzed (after removing HTML tags, collapsing areas of too-many-spaces, etc.).
has an entry per top 3 languages that matched, that includes the percent confidence of the match as well as a separate normalized score.

The module exports these global constants:

list of the encoding names CLD recognizes (if you provide hintEncoding, it must be one of these names).
list of languages and their codes (if you provide hintLanguageCode, it must be one of the codes from these codes).
list of external languages and their codes. Note that external languages cannot be hinted, but may be matched if you pass includeExtendedLanguages=True (the default).
list of all detectable languages, as best I can determine (this was reverse engineered from a unit test, ie it contains a language X if that language was tested and passes for at least one example text).


Please see AUTHORS.

Reporting bugs

Please see BUG_REPORTS.




Please see LICENSE.

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cld2-cffi-0.1.4.tar.gz (17.6 MB) Copy SHA256 Checksum SHA256 Source Aug 9, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting