skillfed

pycld2

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

pycld2 v0.42 774.2K downloads/30d#5,096 on PyPI179
Permissive license Apache2 AGING released

What it is and what it does

pycld2 is a Python wrapper around Google's Compact Language Detect 2 (CLD2), a C++ library that identifies the language of text. It consolidates the upstream CLD2 library with its bindings into a single pip-installable package, supporting detection across over 165 languages by default. The package exposes a single primary function, `detect()`, which takes UTF-8 text (as str or bytes) and returns a reliability flag, byte count, and a list of detected languages with confidence scores. Optionally, it can return byte-range vectors showing which language was detected in which part of the input, and accepts hints (top-level domain, language preference, encoding) to influence detection.

The package is built on precompiled wheels for Python 3.8–3.12 across macOS, Linux, and Windows, eliminating the need to compile C++ locally in most cases. It has no runtime dependencies beyond the C++ bindings. The API is minimal and straightforward: call `detect()` with your text and optional parameters, and receive structured results. It is useful for applications that need fast, lightweight language identification without the overhead of neural models, though the aging maintenance status (last release 504 days ago) means it may not have been tested against the very latest Python patch releases.

Use it for:

  • Automatically categorize user-generated content by language in multilingual web applications or content management systems.
  • Pre-process text corpora for natural language processing pipelines by filtering or routing documents to language-specific models.
  • Detect language in HTTP requests or HTML documents, using optional hints from domain or HTTP headers to improve accuracy.
  • Identify the primary language in mixed-language documents and extract byte ranges showing where each language appears.
  • Triage support tickets or chat messages by language to route them to appropriate language-specific teams or handlers.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Detects the language of text using Google's CLD2 library, supporting over 165 languages and returning reliability scores and byte-range vectors.

Yes, if you need lightweight, fast language detection across many languages without external dependencies or neural models. The prebuilt wheels make installation straightforward on common platforms. However, consider the aging maintenance status (last release 504 days ago): verify that it works reliably with your target Python version and that CLD2's detection quality meets your accuracy requirements. If you need state-of-the-art accuracy, CLD3 or neural alternatives may be better; if you need speed and simplicity, pycld2 is a solid choice.

Install

pycld2 on PyPI

pip

pip install pycld2

uv

uv add pycld2

poetry

poetry add pycld2

Installing pycld2

Before you install

Medium install friction due to compiled C++ bindings; prebuilt wheels are available for Python 3.8–3.12 on macOS, Linux (x86_64, i686, musl), and Windows. Last release was 504 days ago; the project is aging but the repository remains active.

License in practice

Licensed under Apache 2.0 (permissive). Safe for commercial and proprietary use with minimal restrictions; attribution and license inclusion are required.

Quickstart

import pycld2 as cld2

isReliable, textBytesFound, details = cld2.detect(
    "а неправильный формат идентификатора дн назад"
)
print(details[0])
# ('RUSSIAN', 'ru', 98, 404.0)

Input must be UTF-8 encoded (str or UTF-8 bytes); non-UTF-8 bytes will raise pycld2.error.

Verify before relying

  • Whether the aging maintenance status (504 days since last release) affects reliability or security for new Python versions beyond 3.12.
  • Performance characteristics and memory footprint for large-scale batch language detection.
  • Accuracy comparison with CLD3 or other modern language detection libraries.

Package facts

License Apache2 (permissive)
Python support not specified
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance aging — 504 days since the last release
Last repo commit
First released
Downloads 774,217/month — #5,096 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pycld2-0.42-cp310-cp310-macosx_11_0_arm64.whl; pycld2-0.42-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; pycld2-0.42-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl; pycld2-0.42-cp310-cp310-musllinux_1_2_i686.whl; pycld2-0.42-cp310-cp310-musllinux_1_2_x86_64.whl; pycld2-0.42-cp310-cp310-win32.whl; pycld2-0.42-cp310-cp310-win_amd64.whl; pycld2-0.42-cp311-cp311-macosx_11_0_arm64.whl; pycld2-0.42-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; pycld2-0.42-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl; pycld2-0.42-cp311-cp311-musllinux_1_2_i686.whl; pycld2-0.42-cp311-cp311-musllinux_1_2_x86_64.whl; pycld2-0.42-cp311-cp311-win32.whl; pycld2-0.42-cp311-cp311-win_amd64.whl; pycld2-0.42-cp312-cp312-macosx_11_0_arm64.whl; pycld2-0.42-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; pycld2-0.42-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl; pycld2-0.42-cp312-cp312-musllinux_1_2_i686.whl; pycld2-0.42-cp312-cp312-musllinux_1_2_x86_64.whl; pycld2-0.42-cp312-cp312-win32.whl

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: C++Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Text Processing :: Linguistic

Tags

language detectiondetect text languagemultilingual language identificationcld2 python bindingscompact language detectidentify document languagelanguage recognition
language-detectionmultilingualtext-processing

More Linguistic packages