1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
=============
python-zstd
=============
.. |releaseW| image:: https://github.com/sergey-dryabzhinsky/python-zstd/actions/workflows/build-wheels.yml/badge.svg?branch=v1.5.5.1
:target: https://github.com/sergey-dryabzhinsky/python-zstd/actions/workflows/build-wheels.yml
.. |masterW| image:: https://github.com/sergey-dryabzhinsky/python-zstd/actions/workflows/build-wheels.yml/badge.svg
:target: https://github.com/sergey-dryabzhinsky/python-zstd/actions/workflows/build-wheels.yml
+---------+------------+
| branch | status |
+=========+============+
| Release | |releaseW| |
+---------+------------+
| Master | |masterW| |
+---------+------------+
Simple python bindings to Yann Collet ZSTD compression library.
**Zstd**, short for Zstandard, is a new lossless compression algorithm,
which provides both good compression ratio *and* speed for your standard compression needs.
"Standard" translates into everyday situations which neither look for highest possible ratio
(which LZMA and ZPAQ cover) nor extreme speeds (which LZ4 covers).
It is provided as a BSD-license package, hosted on GitHub_.
.. _GitHub: https://github.com/facebook/zstd
WARNING!!!
----------
If you setup 1.0.0.99.1 version - remove it manualy to able to update.
PIP matching version strings not tuple of numbers.
Result generated by versions prior to 1.0.0.99.1 is not compatible with orignial Zstd
by any means. It generates custom header and can be read only by zstd python module.
As of 1.0.0.99.1 version it uses standard Zstd output, not modified.
To prevent data loss there is two functions now: ```compress_old``` and ```decompress_old```.
They are works just like in old versions prior to 1.0.0.99.1.
As of 1.1.4 version module build without them by default.
As of 1.3.4 version these functions are deprecated and will be removed in future releases.
As of 1.5.0 version these functions are removed.
DISCLAIMER
__________
These python bindings are kept simple and blunt.
Support of dictionaries and streaming is not planned.
LINKS
-----
* Zstandard: https://github.com/facebook/zstd
* More full-featured and compatible with Zstandard python bindings by Gregory Szorc: https://github.com/indygreg/python-zstandard
Build from source
-----------------
>>> $ git clone https://github.com/sergey-dryabzhinsky/python-zstd
>>> $ git submodule update --init
>>> $ apt-get install python-dev python3-dev python-setuptools python3-setuptools
>>> $ python setup.py build_ext clean
>>> $ python3 setup.py build_ext clean
Note: Zstd legacy format support disabled by default.
To build with Zstd legacy versions support - pass ``--legacy`` option to setup.py script:
>>> $ python setup.py build_ext --legacy clean
When using a PEP 517 builder you can use ``ZSTD_LEGACY`` environment variable instead:
>>> $ ZSTD_LEGACY=1 python -m build -w
Note: Python-Zstd legacy format support removed since 1.5.0.
If you need to convert old data - checkout 1.4.9.1 module version. Support of it disabled by default.
To build with python-zstd legacy format support (pre 1.1.2) - pass ``--pyzstd-legacy`` option to setup.py script:
>>> $ python setup.py build_ext --pyzstd-legacy clean
If you want to build with existing distribution of libzstd just add ``--external`` option.
But beware! Legacy formats support state is unknown in this case.
And if your version not equal with python-zstd - tests may not pass.
>>> $ python setup.py build_ext --external clean
When using a PEP 517 builder you can use ``ZSTD_EXTERNAL`` environment variable instead:
>>> $ ZSTD_EXTERNAL=1 python -m build -w
If paths to header file ``zstd.h`` and libraries is uncommon - use common ``build`` params:
--libraries --include-dirs --library-dirs.
>>> $ python setup.py build_ext --external --include-dirs /opt/zstd/usr/include --libraries zstd --library-dirs /opt/zstd/lib clean
Install from pypi
-----------------
>>> # for Python 2.7+
>>> $ pip install zstd
>>> # or for Python 3.4+
>>> $ pip3 install zstd
API
___
Error
Standard python Exception for zstd module
ZSTD_compress (data[, level, threads]): string|bytes
Function, compress input data block via mutliple threads, return compressed block, or raises Error.
Params:
* **data**: string|bytes - input data block, length limited by 2Gb by Python API
* **level**: int - compression level, ultra-fast levels from -100 (ultra) to -1 (fast) available since zstd-1.3.4, and from 1 (fast) to 22 (slowest), 0 or unset - means default (3). Default - 3.
* **threads**: int - how many threads to use, from 0 to 200, 0 or unset - auto-tune by cpu cores count. Default - 0. Since: 1.4.4.1
Aliases: *compress(...)*, *dumps(...)*
Exception if:
- level bigger than max level
Max number of threads:
- 32bit system: 64
- 64bit system: 256
If provided bigger number - silemtly set maximum number (since 1.5.4.1)
Since: 0.1
ZSTD_uncompress (data): string|bytes
Function, decompress input compressed data block, return decompressed block, or raises Error.
Support compressed data with multiple/concatenated frames (blocks) (since 1.5.5.1).
Params:
* **data**: string|bytes - input compressed data block, length limited by 2Gb by Python API
Aliases: *decompress(...)*, *uncompress(...)*, *loads(...)*
Since: 0.1
version (): string|bytes
Returns this module doted version string.
The first three digits are folow libzstd version.
Fourth digit - module release number for that version.
Since: 1.3.4.3
ZSTD_version (): string|bytes
Returns ZSTD library doted version string.
Since: 1.3.4.3
ZSTD_version_number (): int
Returns ZSTD library version in format: MAJOR*100*100 + MINOR*100 + RELEASE.
Since: 1.3.4.3
ZSTD_threads_count (): int
Returns ZSTD determined CPU cores count.
Since: 1.5.4.1
ZSTD_max_threads_count (): int
Returns ZSTD library determined maximum working threads count.
Since: 1.5.4.1
ZSTD_external (): int
Returns 0 of 1 if ZSTD library build as external.
Since: 1.5.0.2
Removed
_______
ZSTD_compress_old (data[, level]): string|bytes
Function, compress input data block, return compressed block, or raises Error.
**DEPRECATED**: Returns not compatible with ZSTD block header
**REMOVED**: since 1.5.0
Params:
* **data**: string|bytes - input data block, length limited by 2Gb by Python API
* **level**: int - compression level, ultra-fast levels from -5 (ultra) to -1 (fast) available since zstd-1.3.4, and from 1 (fast) to 22 (slowest), 0 or unset - means default (3). Default - 3.
Since: 1.0.0.99.1
ZSTD_uncompress_old (data): string|bytes
Function, decompress input compressed data block, return decompressed block, or raises Error.
**DEPRECATED**: Accepts data with not compatible with ZSTD block header
**REMOVED**: since 1.5.0
Params:
* **data**: string|bytes - input compressed data block, length limited by 2Gb by Python API
Since: 1.0.0.99.1
Use
___
Module has simple API:
>>> import zstd
>>> dir(zstd)
['Error', 'ZSTD_compress', 'ZSTD_external', 'ZSTD_uncompress', 'ZSTD_version', 'ZSTD_version_number', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'compress', 'decompress', 'dumps', 'loads', 'uncompress', 'version']
>>> zstd.version()
'1.5.1.0'
>>> zstd.ZSTD_version()
'1.5.1'
>>> zstd.ZSTD_version_number()
10501
>>> zstd.ZSTD_external()
0
In python2
>>> data = "123456qwert"
In python3 use bytes
>>> data = b"123456qwert"
>>> cdata = zstd.compress(data, 1)
>>> data == zstd.decompress(cdata)
True
>>> cdata_mt = zstd.compress(data, 1, 4)
>>> cdata == cdata_mt
True
>>> data == zstd.decompress(cdata_mt)
True
|