Coder Social home page Coder Social logo

python-snappy's Introduction

python-snappy

Python library for the snappy compression library from Google. This library is distributed under the New BSD License (http://www.opensource.org/licenses/bsd-license.php).

Dependencies

To use with pypy:

Build & Install

Build:

python setup.py build

Install:

python setup.py install

Or install it from PyPi:

pip install python-snappy

Run tests

# run python snappy tests
nosetest test_snappy.py

# support for cffi backend
nosetest test_snappy_cffi.py

Benchmarks

snappy vs. zlib

Compressing:

%timeit zlib.compress("hola mundo cruel!")
100000 loops, best of 3: 9.64 us per loop

%timeit snappy.compress("hola mundo cruel!")
1000000 loops, best of 3: 849 ns per loop

Snappy is 11 times faster than zlib when compressing

Uncompressing:

r = snappy.compress("hola mundo cruel!")

%timeit snappy.uncompress(r)
1000000 loops, best of 3: 755 ns per loop

r = zlib.compress("hola mundo cruel!")

%timeit zlib.decompress(r)
1000000 loops, best of 3: 1.11 us per loop

Snappy is twice as fast as zlib

Commandline usage

You can invoke Python Snappy to compress or decompress files or streams from the commandline after installation as follows

Compressing and decompressing a file:

$ python -m snappy -c uncompressed_file compressed_file.snappy
$ python -m snappy -d compressed_file.snappy uncompressed_file

Compressing and decompressing a stream:

$ cat uncompressed_data | python -m snappy -c > compressed_data.snappy
$ cat compressed_data.snappy | python -m snappy -d > uncompressed_data

You can get help by running

$ python -m snappy --help
Snappy - compression library from Google (c)
http://code.google.com/p/snappy

Frequently Asked Questions

How to install it on Mac OS X?

It has been reported a few times (Issue #7 and #23) that it can't be installed correctly the library in Mac. The procedure should be,

$ brew install snappy # snappy library from Google
$ CPPFLAGS="-I/usr/local/include -L/usr/local/lib" pip install python-snappy

python-snappy's People

Contributors

andrix avatar bos avatar jtolio avatar nathanmoore avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.