Skip to main content

A Python bindings for Zopfli

Project description

A Python bindings for Zopfli.

https://img.shields.io/pypi/v/zopflipy.svg https://github.com/hattya/zopflipy/actions/workflows/ci.yml/badge.svg https://semaphoreci.com/api/v1/hattya/zopflipy/branches/master/badge.svg https://ci.appveyor.com/api/projects/status/98a7e7d6qlkvs6vl/branch/master?svg=true https://codecov.io/gh/hattya/zopflipy/branch/master/graph/badge.svg

Installation

$ pip install zopflipy

Requirements

  • Python 3.7+

  • setuptools

Usage

ZopfliCompressor

>>> import zopfli
>>> c = zopfli.ZopfliCompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> z = c.compress(b'Hello, world!') + c.flush()
>>> d = zopfli.ZopfliDecompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> d.decompress(z) + d.flush()
b'Hello, world!''

ZopfliDeflater

>>> import zopfli
>>> c = zopfli.ZopfliDeflater()
>>> z = c.compress(b'Hello, world!') + c.flush()
>>> d = zopfli.ZopfliDecompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> d.decompress(z) + d.flush()
b'Hello, world!''

ZopfliPNG

>>> import zopfli
>>> png = zopfli.ZopfliPNG()
>>> with open('in.png', 'rb') as fp:
...     data = fp.read()
>>> len(png.optimize(data)) < len(data)
True

ZipFile

A subclass of zipfile.ZipFile which uses ZopfliCompressor for the zipfile.ZIP_DEFLATED compression method.

>>> import zipfile
>>> import zopfli
>>> with zopfli.ZipFile('a.zip', 'w', zipfile.ZIP_DEFLATED) as zf:
...     zf.writestr('a.txt', b'Hello, world!')

License

ZopfliPy is distributed under the terms of the Apache License, Version 2.0.

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

zopflipy-1.8.zip (208.5 kB view hashes)

Uploaded source

Built Distributions

zopflipy-1.8-cp311-cp311-win_amd64.whl (102.4 kB view hashes)

Uploaded cp311

zopflipy-1.8-cp311-cp311-win32.whl (82.3 kB view hashes)

Uploaded cp311

zopflipy-1.8-cp310-cp310-win_amd64.whl (102.4 kB view hashes)

Uploaded cp310

zopflipy-1.8-cp310-cp310-win32.whl (82.3 kB view hashes)

Uploaded cp310

zopflipy-1.8-cp39-cp39-win_amd64.whl (102.4 kB view hashes)

Uploaded cp39

zopflipy-1.8-cp39-cp39-win32.whl (82.3 kB view hashes)

Uploaded cp39

zopflipy-1.8-cp38-cp38-win_amd64.whl (102.4 kB view hashes)

Uploaded cp38

zopflipy-1.8-cp38-cp38-win32.whl (82.3 kB view hashes)

Uploaded cp38

zopflipy-1.8-cp37-cp37m-win_amd64.whl (102.4 kB view hashes)

Uploaded cp37

zopflipy-1.8-cp37-cp37m-win32.whl (82.3 kB view hashes)

Uploaded cp37

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page