Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

pycld3

Python bindings to the Compact Language Detector v3 (CLD3).

CircleCI License PyPI Wheel Status Python Implementation

This package contains Python bindings (via Cython) to Google's CLD3 library.

>>> import cld3
>>> cld3.get_language("影響包含對氣候的變化以及自然資源的枯竭程度")
LanguagePrediction(language='zh', probability=0.999969482421875, is_reliable=True, proportion=1.0)

Installing with Wheels: Supported Versions and Platforms

This project supports CPython versions 3.5 through 3.8.

We publish wheels for the following matrix:

  • MacOS 10.13 and 10.15: CPython 3.5, 3.6, 3.7, and 3.8.
  • Linux: CPython 3.5, 3.6, 3.7, and 3.8; the wheels are manylinux1 x86-64 wheels, so should work on a varity of Linux variants.

The wheels for both MacOS and manylinux1 include the external protobuf library copied into the wheel itself via auditwheel or delocate so that you won't need to install any extra non-PyPI dependencies.

If you are installing on one of the variants listed above, you should not need to have protoc or libprotobuf installed. All you need is a recent version (19 or later) of pip:

python -m pip install -U pycld3

Installing from Source: Prerequisites

If you are not on a platform variant that is eligible to use a wheel, you may still be able to use pycld3 via its source distribution (tar.gz), but a bit more work is required to install. Namely, you'll also need:

  • the Protobuf compiler (the protoc executable)
  • the Protobuf development headers and libprotoc library
  • a compiler, preferably g++

Please consult the official protobuf repository for information on installing Protobuf. The project contains an Installation README that covers installation on Windows and Unix.

If for whatever reason you are on a Unix host but unable to use the wheels (for instance, if you have an i686 architecture), here is a quick-and-dirty guide to installing.

Debian/Ubuntu

sudo apt-get update -y
sudo apt-get install -y --no-install-recommends \
    g++ \
    protobuf-compiler \
    libprotobuf-dev
python -m pip install -U pycld3

Alpine Linux

Note: Alpine Linux does not support PyPI wheels as of April 2020. The steps below are mandatory on Alpine Linux because you will need to install from the source distribution. If the situation permits, using a Debian distro should be much easier (and faster).

apk --update add g++ protobuf protobuf-dev
python -m pip install -U pycld3

CentOS/RHEL

Install from source, as root/UID 0:

sudo su -
set -ex
pushd /opt
PROTOBUF_VERSION='3.11.4'
yum update -y
yum install -y autoconf automake gcc-c++ glibc-headers gzip libtool make python3-devel zlib-devel
curl -Lo /opt/protobuf.tar.gz \
    "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz"
tar -xzvf protobuf.tar.gz
rm -f protobuf.tar.gz
pushd "protobuf-${PROTOBUF_VERSION}"
./configure --with-zlib --disable-debug && make && make install && ldconfig --verbose
popd && rm -rf "protobuf-${PROTOBUF_VERSION}" && popd && set +ex

python -m pip install -U pycld3

Note: the steps above are for CentOS 8. For earlier versions, you may need to replace:

  • gcc-c++ with g++
  • python3-devel with python-devel

MacOS/Homebrew

brew update
brew upgrade protobuf || brew install -v protobuf
python -m pip install -U pycld3

Windows

Please consult Protobuf's C++ Installation - Windows section for help with installing Protobuf on Windows.

If you would like to help contribute Windows wheels (preferably as a job within the project's CI/CD pipelines), please file an issue.

Usage

cld3 exports two module-level functions, get_language() and get_frequent_languages():

>>> import cld3

>>> cld3.get_language("影響包含對氣候的變化以及自然資源的枯竭程度")
LanguagePrediction(language='zh', probability=0.999969482421875, is_reliable=True, proportion=1.0)

>>> cld3.get_language("This is a test")
LanguagePrediction(language='en', probability=0.9999980926513672, is_reliable=True, proportion=1.0)

>>> for lang in cld3.get_frequent_languages(
...     "This piece of text is in English. Този текст е на Български.",
...     num_langs=3
... ):
...     print(lang)
...
LanguagePrediction(language='bg', probability=0.9173890948295593, is_reliable=True, proportion=0.5853658318519592)
LanguagePrediction(language='en', probability=0.9999790191650391, is_reliable=True, proportion=0.4146341383457184)

FAQ

cld3 incorrectly detects my input. How can I fix this?

A first resort is to preprocess (clean) your input text based on conditions specific to your program.

A salient example is to remove URLs and email addresses from the input. CLD3 (unlike CLD2) does almost none of this cleaning for you, in the spirit of not penalizing other users with overhead that they may not need.

Here's such an example using a simplified URL regex from Regular Expressions Cookbook, 2nd ed.:

>>> import re
>>> import cld3

# cld3 does not ignore the URL components by default
>>> s = "Je veux que: https://site.english.com/this/is/a/url/path/component#fragment"
>>> cld3.get_language(s)
LanguagePrediction(language='en', probability=0.5319557189941406, is_reliable=False, proportion=1.0)

>>> url_re = r"\b(?:https?://|www\.)[a-z0-9-]+(\.[a-z0-9-]+)+(?:[/?].*)?"
>>> new_s = re.sub(url_re, "", s)
>>> new_s
'Je veux que: '
>>> cld3.get_language(new_s)
LanguagePrediction(language='fr', probability=0.9799421429634094, is_reliable=True, proportion=1.0)

Note: This URL regex aims for simplicity. It requires a domain name, and doesn't allow a username or password; it allows the scheme (http or https) to be omitted if it can be inferred from the subdomain (www). Source: Regular Expressions Cookbook, 2nd ed. - Goyvaerts & Levithan.

In some other cases, you cannot fix the incorrect detection. Language detection algorithms in general may perform poorly with very short inputs. Rarely should you trust the output of something like detect("hi"). Keep this limitation in mind regardless of what library you are using.

Please remember that, at the end of the day, this project is just a Python wrapper to the CLD3 C++ library that does the actual heavy-lifting.

I'm seeing an error during pip installation. How can I fix this?

First, please make sure you have read the installation section that that you have installed Protobuf if necessary.

If that doesn't help, please file an issue in this repository. The build process for this project is somewhat complex because it involves both Cython and Protobuf, but I do my best to make it work everywhere possible.

Protobuf is installed, but I'm still seeing "cannot open shared object file"

If you've installed Protobuf, but are seeing an error such as:

ImportError: libprotobuf.so.22: cannot open shared object file: No such file or directory

This likely means that Python is not finding the libprotobuf shared object, possibly because ldconfig didn't do what it was supposed to. You may need to tell it where to look.

You can find where the library sits via:

$ find /usr -name 'libprotoc.so' \( -type l -o -type f \)
/usr/local/lib/libprotoc.so

Then, you can add the directory containing this file to LD_LIBRARY_PATH:

export LD_LIBRARY_PATH="$(dirname $(find /usr -name 'libprotoc.so' \( -type l -o -type f \))):$LD_LIBRARY_PATH"

You can quickly test that this worked:

$ python -c 'import cld3; print(cld3.get_language("影響包含對氣候的變化以及自然資源的枯竭程度"))'
LanguagePrediction(language='zh', probability=0.999969482421875, is_reliable=True, proportion=1.0)

Authors

This repository contains a fork of google/cld3 at commit 06f695f. The license for google/cld3 can be found at LICENSES/CLD3_LICENSE.

This repository is a combination of changes introduced by various forks of google/cld3 by the following people:

Metadata

Release files for pycld3 0.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycld3 0.20
File Size Uploaded Provenance Actions
pycld3-0.20.tar.gz 695.3 kB Without provenance Details for pycld3-0.20.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pycld3 0.20
File Actions
pycld3-0.20-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details for pycld3-0.20-cp38-cp38-manylinux1_x86_64.whl
pycld3-0.20-cp38-cp38-macosx_10_15_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.15+ x86-64 Details for pycld3-0.20-cp38-cp38-macosx_10_15_x86_64.whl
pycld3-0.20-cp38-cp38-macosx_10_13_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.13+ x86-64 Details for pycld3-0.20-cp38-cp38-macosx_10_13_x86_64.whl
pycld3-0.20-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details for pycld3-0.20-cp37-cp37m-manylinux1_x86_64.whl
pycld3-0.20-cp37-cp37m-macosx_10_15_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64 Details for pycld3-0.20-cp37-cp37m-macosx_10_15_x86_64.whl
pycld3-0.20-cp37-cp37m-macosx_10_13_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.13+ x86-64 Details for pycld3-0.20-cp37-cp37m-macosx_10_13_x86_64.whl
pycld3-0.20-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details for pycld3-0.20-cp36-cp36m-manylinux1_x86_64.whl
pycld3-0.20-cp36-cp36m-macosx_10_15_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64 Details for pycld3-0.20-cp36-cp36m-macosx_10_15_x86_64.whl
pycld3-0.20-cp36-cp36m-macosx_10_13_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64 Details for pycld3-0.20-cp36-cp36m-macosx_10_13_x86_64.whl
pycld3-0.20-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details for pycld3-0.20-cp35-cp35m-manylinux1_x86_64.whl
pycld3-0.20-cp35-cp35m-macosx_10_15_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.15+ x86-64 Details for pycld3-0.20-cp35-cp35m-macosx_10_15_x86_64.whl
pycld3-0.20-cp35-cp35m-macosx_10_13_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.13+ x86-64 Details for pycld3-0.20-cp35-cp35m-macosx_10_13_x86_64.whl

Total release size: 64.1 MB

Release files / pycld3-0.20.tar.gz

Download URL pycld3-0.20.tar.gz
Size 695.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8c10d78c8f1d81ee1f9649971ed14e87f2550ea40feb1f66df375a426a6d9986
BLAKE2b-256 checksum
How to use checksums
21143e56ece4e48b0feb09e8c7c4e8bd6cb7beecb2d0329070a3515b1297e551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp38-cp38-manylinux1_x86_64.whl

Download URL pycld3-0.20-cp38-cp38-manylinux1_x86_64.whl
Size 13.3 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
1e4d51b510cf7bab526f0e35771ef2dc68444c2a5966b618f9b1657aaea349fe
BLAKE2b-256 checksum
How to use checksums
4af3fa3752df39172790fbb8e24a2fb4df4f08b2f8d0134ce8d29ea3ef45b7ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp38-cp38-macosx_10_15_x86_64.whl

Download URL pycld3-0.20-cp38-cp38-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.8 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
bb9cff903cf7b77076cb1fd575636253c2f1eef8c9673036393cc5295521d49b
BLAKE2b-256 checksum
How to use checksums
9121e267d857f3f6feb575bcc3e1466fe63bdee67762e7e9ee3c6f01b8d29ea9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp38-cp38-macosx_10_13_x86_64.whl

Download URL pycld3-0.20-cp38-cp38-macosx_10_13_x86_64.whl
Size 1.3 MB
Tags CPython 3.8 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
617ea7a75659704b3494169639604c5f5f36bd8b9f3ce5f8d956c07e4ec4f818
BLAKE2b-256 checksum
How to use checksums
1c9bbe981201d37ce790d9bb67afba27fc6fbc6399e3edd8beb9a06bc7031615
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp37-cp37m-manylinux1_x86_64.whl

Download URL pycld3-0.20-cp37-cp37m-manylinux1_x86_64.whl
Size 13.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
5b7bb88a333f304f953f535103b17a5a3c4dff2eec76cf6cb761a068c1d8a487
BLAKE2b-256 checksum
How to use checksums
fc4556b7b296b5fe7ba139574289e2c4e8ee91962cb86125b176cc199b03571b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp37-cp37m-macosx_10_15_x86_64.whl

Download URL pycld3-0.20-cp37-cp37m-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
9884afec5b54ee5946ea61041dca82c65d6c047136943ec4a69ea0a9b2fe0268
BLAKE2b-256 checksum
How to use checksums
8061b99efa9aeb27ff3f138da6005d9be7624d2877bb885b301fcff095ff40bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp37-cp37m-macosx_10_13_x86_64.whl

Download URL pycld3-0.20-cp37-cp37m-macosx_10_13_x86_64.whl
Size 1.3 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
786ffacd0585901c7c255f04bc25d55dfb33aee6e7554fec3953e2f7b9d18258
BLAKE2b-256 checksum
How to use checksums
28d43eb6a9e09e16ed290d9d238d77a81105a42e96784e17a867570080978d1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp36-cp36m-manylinux1_x86_64.whl

Download URL pycld3-0.20-cp36-cp36m-manylinux1_x86_64.whl
Size 13.3 MB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
160919326d7b9e4555a5cbd2b40887eff42f3196296df3df5dc10d2c288a63db
BLAKE2b-256 checksum
How to use checksums
da2817938836d8bfcc621068c332555d4fba57bb7bbba5734e6991ca6a4a36a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp36-cp36m-macosx_10_15_x86_64.whl

Download URL pycld3-0.20-cp36-cp36m-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
e15af2fb4049d3f2cb173081eac3a54dd10e59ab731a246971ee7e19515765e6
BLAKE2b-256 checksum
How to use checksums
b030b11631c27b19312f0cfe356d3af9b4571aea2e1200452d0d423e5642a7dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp36-cp36m-macosx_10_13_x86_64.whl

Download URL pycld3-0.20-cp36-cp36m-macosx_10_13_x86_64.whl
Size 1.3 MB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
b82880f9bc85cf8fe1989755f91a441c670fc14d8bc5305f2af72af0e13bcb96
BLAKE2b-256 checksum
How to use checksums
dc76845a7fcb8efb97066342fbeda00dd56dabcdd170e710b9c0a4fa66e049d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp35-cp35m-manylinux1_x86_64.whl

Download URL pycld3-0.20-cp35-cp35m-manylinux1_x86_64.whl
Size 13.3 MB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
58c78ad311a31fa274e98bc89d1d87150c1c7f381aaccefcf11b4f1aa1537689
BLAKE2b-256 checksum
How to use checksums
ff9cda4f1832f82bd74368c839ded07462600a5bed77ef3c48d3c6d5e16d0524
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp35-cp35m-macosx_10_15_x86_64.whl

Download URL pycld3-0.20-cp35-cp35m-macosx_10_15_x86_64.whl
Size 1.3 MB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
b9140ecb892941d4ce2da05c7e21139e2f9fe7b184f3ecf2dba2ea5e996beb48
BLAKE2b-256 checksum
How to use checksums
e004542743d71a8e3b717877185afa5916b0dd366d129463c11f776960393f62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Release files / pycld3-0.20-cp35-cp35m-macosx_10_13_x86_64.whl

Download URL pycld3-0.20-cp35-cp35m-macosx_10_13_x86_64.whl
Size 1.3 MB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
4e6f9339eb9a908a2f32ee53cbf02f05dd19e67b465833449bc27182390bcd6b
BLAKE2b-256 checksum
How to use checksums
902e6e6633c0277fae785f42a7a4cee459e299ef992ce10a58ca58a2de058d5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

Security for pycld3 0.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page