Skip to content

Commit

Permalink
feat: Add support for Zstandard files, closes #1224
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Feb 15, 2024
1 parent 23f8abf commit c874ebe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

* feat: Add support for Zstandard files with the ``.zst`` extension, if the ``zstandard`` package is installed.
* feat: :doc:`/scripts/csvformat` adds a :code:`--out-asv` (:code:`--A`) option to use the ASCII unit separator and record separator.

1.4.0 - February 13, 2024
Expand Down
9 changes: 8 additions & 1 deletion csvkit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

from csvkit.exceptions import ColumnIdentifierError, RequiredHeaderError

try:
import zstandard
except ImportError:
zstandard = None


class LazyFile:
"""
Expand Down Expand Up @@ -250,8 +255,10 @@ def _open_input_file(self, path, opened=False):
func = gzip.open
elif extension == '.bz2':
func = bz2.open
elif extension == ".xz":
elif extension == '.xz':
func = lzma.open
elif extension == '.zst' and zstandard:
func = zstandard.open
else:
func = open

Expand Down
6 changes: 6 additions & 0 deletions docs/tutorial/1_getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Installing csvkit is easy:
If you have problems installing, look for help in the :doc:`../tricks` section of the documentation.

If you need to work with `Zstandard <https://facebook.github.io/zstd/>`_ files with the ``.zst`` extension, install Zstandard support:

.. code-block:: bash
sudo pip install csvkit[zstandard]
.. note::

If you're familiar with `virtualenv <https://virtualenv.readthedocs.org/en/latest/>`_, it is better to install csvkit in its own environment. If you are doing this, then you should leave off the ``sudo`` in the previous command.
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
'importlib_metadata; python_version < "3.10"',
],
extras_require={
'zstandard': [
'zstandard',
],
'test': [
'coverage>=4.4.2',
'pytest',
Expand Down

0 comments on commit c874ebe

Please sign in to comment.