Skip to main content

Columnar and compressed data containers.

Project description

bcolz: columnar and compressed data containers

Gitter Version Documentation Build: Travis Coverage License: BSD Twitter: @ml4t Blosc

bcolz provides columnar, chunked data containers that can be compressed either in-memory and on-disk. Column storage allows for efficiently querying tables, as well as for cheap column addition and removal. It is based on [NumPy](http://www.numpy.org), and uses it as the standard data container to communicate with bcolz objects, but it also comes with support for import/export facilities to/from [HDF5/PyTables tables](http://www.pytables.org) and [pandas dataframes](http://pandas.pydata.org).

bcolz objects are compressed by default not only for reducing memory/disk storage, but also to improve I/O speed. The compression process is carried out internally by Blosc, a high-performance, multithreaded meta-compressor that is optimized for binary data (although it works with text data just fine too).

bcolz can also use numexpr internally (it does that by default if it detects numexpr installed) or dask so as to accelerate many vector and query operations (although it can use pure NumPy for doing so too). numexpr/dask can optimize the memory usage and use multithreading for doing the computations, so it is blazing fast. This, in combination with carray/ctable disk-based, compressed containers, can be used for performing out-of-core computations efficiently, but most importantly transparently.

Just to whet your appetite, here is an example with real data, where bcolz is already fulfilling the promise of accelerating memory I/O by using compression.

Rationale

By using compression, you can deal with more data using the same amount of memory, which is very good on itself. But in case you are wondering about the price to pay in terms of performance, you should know that nowadays memory access is the most common bottleneck in many computational scenarios, and that CPUs spend most of its time waiting for data. Hence, having data compressed in memory can reduce the stress of the memory subsystem as well.

Furthermore, columnar means that the tabular datasets are stored column-wise order, and this turns out to offer better opportunities to improve compression ratio. This is because data tends to expose more similarity in elements that sit in the same column rather than those in the same row, so compressors generally do a much better job when data is aligned in such column-wise order. In addition, when you have to deal with tables with a large number of columns and your operations only involve some of them, a columnar-wise storage tends to be much more effective because minimizes the amount of data that travels to CPU caches.

So, the ultimate goal for bcolz is not only reducing the memory needs of large arrays/tables, but also making bcolz operations to go faster than using a traditional data container like those in NumPy or Pandas. That is actually already the case in some real-life scenarios (see the notebook above) but that will become pretty more noticeable in combination with forthcoming, faster CPUs integrating more cores and wider vector units.

Requisites

  • Python >= 3.7
  • NumPy >= 1.16.5
  • Cython >= 0.22 (just for compiling the beast)
  • C-Blosc >= 1.8.0 (optional, as the internal Blosc will be used by default)

Optional:

  • numexpr >= 2.5.2
  • dask >= 0.9.0
  • pandas
  • tables (pytables)

Installing as wheel

There are wheels for Linux and Mac OS X that you can install with

pip install bcolz-zipline

Then also install NumPy with

pip install numpy

and test your installation with

python -c 'import bcolz;bcolz.test()'

Building

There are different ways to compile bcolz, depending if you want to link with an already installed Blosc library or not.

Compiling with an installed Blosc library (recommended)

Python and Blosc-powered extensions have a difficult relationship when compiled using GCC, so this is why using an external C-Blosc library is recommended for maximum performance (for details, see https://github.com/Blosc/python-blosc/issues/110).

Go to https://github.com/Blosc/c-blosc/releases and download and install the C-Blosc library. Then, you can tell bcolz where is the C-Blosc library in a couple of ways:

Using an environment variable:

$ BLOSC_DIR=/usr/local     (or "set BLOSC_DIR=\blosc" on Win)
$ export BLOSC_DIR         (not needed on Win)
$ python setup.py build_ext --inplace

Using a flag:

$ python setup.py build_ext --inplace --blosc=/usr/local

Compiling without an installed Blosc library

bcolz also comes with the Blosc sources with it so, assuming that you have a C++ compiler installed, do:

$ python setup.py build_ext --inplace

That's all. You can proceed with testing section now.

Note: The requirement for the C++ compiler is just for the Snappy dependency. The rest of the other components of Blosc are pure C (including the LZ4 and Zlib libraries).

Testing

After compiling, you can quickly check that the package is sane by running:

$ PYTHONPATH=.   (or "set PYTHONPATH=." on Windows)
$ export PYTHONPATH    (not needed on Windows)
$ python -c"import bcolz; bcolz.test()"  # add `heavy=True` if desired

Installing

Install it as a typical Python package:

$ pip install -U .

Optionally Install the additional dependencies:

$ pip install .[optional]

Documentation

You can find the online manual at:

http://bcolz.blosc.org

but of course, you can always access docstrings from the console (i.e. help(bcolz.ctable)).

Also, you may want to look at the bench/ directory for some examples of use.

Resources

Visit the main bcolz site repository at: http://github.com/Blosc/bcolz

Home of Blosc compressor: http://blosc.org

User's mail list: http://groups.google.com/group/bcolz (bcolz@googlegroups.com)

An introductory talk (20 min) about bcolz at EuroPython

  1. Slides here.

License

Please see BCOLZ.txt in LICENSES/ directory.

Share your experience

Let us know of any bugs, suggestions, gripes, kudos, etc. you may have.

Enjoy Data!

Project details


Download files

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

Source Distribution

bcolz-zipline-1.2.3.tar.gz (1.4 MB view hashes)

Uploaded Source

Built Distributions

bcolz_zipline-1.2.3-cp39-cp39-win_amd64.whl (577.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

bcolz_zipline-1.2.3-cp39-cp39-manylinux2010_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

bcolz_zipline-1.2.3-cp39-cp39-manylinux1_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.9

bcolz_zipline-1.2.3-cp39-cp39-macosx_10_9_x86_64.whl (948.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

bcolz_zipline-1.2.3-cp38-cp38-win_amd64.whl (577.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

bcolz_zipline-1.2.3-cp38-cp38-manylinux2010_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

bcolz_zipline-1.2.3-cp38-cp38-manylinux1_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.8

bcolz_zipline-1.2.3-cp38-cp38-macosx_10_9_x86_64.whl (959.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

bcolz_zipline-1.2.3-cp37-cp37m-win_amd64.whl (569.6 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

bcolz_zipline-1.2.3-cp37-cp37m-manylinux2010_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

bcolz_zipline-1.2.3-cp37-cp37m-manylinux1_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.7m

bcolz_zipline-1.2.3-cp37-cp37m-macosx_10_9_x86_64.whl (951.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page