Learn to Code via Tutorials on Repl.it!

← Back to all posts
Python ZStandard compression
h
CodeLongAndPros

How to use ZStandard compression in Python.

Y'all might have of Zip, 7zip, GZip or LZMA/XZ.
However, the ZStandard library can compress a 300Mb file down to 50Mb.

There are bindings for ZStandard in PyPi.

To use these, import the ZStandard library:

To one-shot compress a string of bytes, use the ZstdCompresser class:

So, for example, to compress foo.tar, you can do:

You can also use Zstd with a stream of bytes, for example enabling the use of TQDM. From the docs:

And that's my tutorial on ZStandard. It's not terribly long, but thats because there's not much to cover.

Voters
HahaYes
Highwayman
CodeLongAndPros
Comments
hotnewtop
HahaYes

Comment

CodeLongAndPros
CodeLongAndPros

Aaaand…
No comments.