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!

Lempel-Ziv complexity for a binary sequence, in naive Python code.

Project Description

This repository contains a small, simple and efficient implement of the Lempel-Ziv complexity algorithm.


Simple usage

If the file is accessible in your PATH or in Python’s path:

>>> from lempel_ziv_complexity import lempel_ziv_complexity
>>> s = '1001111011000010'
>>> lempel_ziv_complexity(s)  # 1 / 0 / 01 / 1110 / 1100 / 0010


See this file.

With the C extension

If the file is accessible in your PATH or in Python’s path, the same can be used.

Small benchmark

There is also a Cython version, to have a faster implementation:

$ ipython
>>> s = '1001111011000010'
>>> %timeit lempel_ziv_complexity(s)
6.1 µs ± 33.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
>>> %timeit lempel_ziv_complexity_cython(s)
132 ns ± 2.55 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

The speedup is typically between x50 and x100. It is not shipped with the PyPi version, see directly on GitHub if needed.

Demo on a Jupyter notebook

See this notebook: on nbviewever.

Install and build

Manually ?


Clone this repository, go in the folder, compile, test, and if it works, install it.

cd /tmp/
git clone
cd Lempel-Ziv_Complexity/src/
make build
make test     # should pass
make install  # mv the build/lib*/*.so files where you need them

Be sure to include the dynamic library when you need it, or in a folder accessible by your Python interpreter (somewhere in sys.path). The file is (for Python 2) or the (for Python 3.5, or higher, adapt the name).

With pip ?

This project is hosted on the Pypi package repository.

sudo pip install lempel_ziv_complexity
python -c "from lempel_ziv_complexity import lempel_ziv_complexity; print(lempel_ziv_complexity('1001111011000010') == 6)"  # test



Python v2.7+ or Python v3.1+.

  • Numba can be used to speed up the pure Python version.
  • Cython is needed to build the C extension (faster).

License ?

MIT Licensed (file LICENSE). © Lilian Besson, 2017.

Release History

Release History

This version
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
Lempel_Ziv_Complexity-0.1-py2.py3-none-any.whl (6.4 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Jun 1, 2017
Lempel-Ziv_Complexity-0.1.tar.gz (2.4 kB) Copy SHA256 Checksum SHA256 Source Jun 1, 2017

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