Permalink
Newer
Older
100644 129 lines (75 sloc) 2.31 KB
1
python-snappy
2
=============
3
4
Python library for the snappy compression library from Google.
5
This library is distributed under the New BSD License
6
(http://www.opensource.org/licenses/bsd-license.php).
@andrix
May 26, 2011
8
Dependencies
9
============
10
11
* snappy library >= 1.0.2 (or revision 27)
12
http://code.google.com/p/snappy/
13
@andrix
Jan 11, 2014
15
16
* cffi >= 0.7
17
http://cffi.readthedocs.org/
18
19
* Supports Python 2.7 and Python 3
20
21
Build & Install
22
===============
23
24
Build:
@andrix
Mar 29, 2011
25
26
::
@andrix
Mar 29, 2011
27
28
python setup.py build
29
30
Install:
31
@andrix
Mar 29, 2011
32
::
@andrix
Mar 29, 2011
33
34
python setup.py install
35
36
37
Or install it from PyPi:
38
39
::
41
pip install python-snappy
42
43
Run tests
44
=========
@andrix
Mar 29, 2011
46
::
@andrix
Mar 29, 2011
47
49
nosetest test_snappy.py
51
# support for cffi backend
52
nosetest test_snappy_cffi.py
53
54
Benchmarks
55
==========
56
57
*snappy vs. zlib*
58
@andrix
Mar 29, 2011
59
**Compressing:**
60
61
::
62
63
%timeit zlib.compress("hola mundo cruel!")
64
100000 loops, best of 3: 9.64 us per loop
65
66
%timeit snappy.compress("hola mundo cruel!")
67
1000000 loops, best of 3: 849 ns per loop
68
69
**Snappy** is **11 times faster** than zlib when compressing
@andrix
Mar 29, 2011
70
71
**Uncompressing:**
@andrix
Mar 29, 2011
73
::
74
75
r = snappy.compress("hola mundo cruel!")
76
77
%timeit snappy.uncompress(r)
78
1000000 loops, best of 3: 755 ns per loop
79
80
r = zlib.compress("hola mundo cruel!")
81
82
%timeit zlib.decompress(r)
83
1000000 loops, best of 3: 1.11 us per loop
84
85
**Snappy** is **twice** as fast as zlib
87
Commandline usage
88
=================
89
90
You can invoke Python Snappy to compress or decompress files or streams from
91
the commandline after installation as follows
92
93
Compressing and decompressing a file:
94
95
::
96
97
$ python -m snappy -c uncompressed_file compressed_file.snappy
98
$ python -m snappy -d compressed_file.snappy uncompressed_file
99
100
Compressing and decompressing a stream:
101
102
::
103
104
$ cat uncompressed_data | python -m snappy -c > compressed_data.snappy
105
$ cat compressed_data.snappy | python -m snappy -d > uncompressed_data
106
107
You can get help by running
108
109
::
110
111
$ python -m snappy --help
112
114
Snappy - compression library from Google (c)
115
http://code.google.com/p/snappy
116
117
Frequently Asked Questions
118
==========================
119
120
**How to install it on Mac OS X?**
121
122
It has been reported a few times (Issue #7 and #23) that it can't be installed correctly the library in Mac.
123
The procedure should be,
124
125
::
126
127
$ brew install snappy # snappy library from Google
128
$ CPPFLAGS="-I/usr/local/include -L/usr/local/lib" pip install python-snappy