Skip to content

Commit c874ebe

Browse files
committed
feat: Add support for Zstandard files, closes #1224
1 parent 23f8abf commit c874ebe

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Unreleased
22
----------
33

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

67
1.4.0 - February 13, 2024

csvkit/cli.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
from csvkit.exceptions import ColumnIdentifierError, RequiredHeaderError
1919

20+
try:
21+
import zstandard
22+
except ImportError:
23+
zstandard = None
24+
2025

2126
class LazyFile:
2227
"""
@@ -250,8 +255,10 @@ def _open_input_file(self, path, opened=False):
250255
func = gzip.open
251256
elif extension == '.bz2':
252257
func = bz2.open
253-
elif extension == ".xz":
258+
elif extension == '.xz':
254259
func = lzma.open
260+
elif extension == '.zst' and zstandard:
261+
func = zstandard.open
255262
else:
256263
func = open
257264

docs/tutorial/1_getting_started.rst

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Installing csvkit is easy:
2222
2323
If you have problems installing, look for help in the :doc:`../tricks` section of the documentation.
2424

25+
If you need to work with `Zstandard <https://facebook.github.io/zstd/>`_ files with the ``.zst`` extension, install Zstandard support:
26+
27+
.. code-block:: bash
28+
29+
sudo pip install csvkit[zstandard]
30+
2531
.. note::
2632

2733
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.

setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
'importlib_metadata; python_version < "3.10"',
7070
],
7171
extras_require={
72+
'zstandard': [
73+
'zstandard',
74+
],
7275
'test': [
7376
'coverage>=4.4.2',
7477
'pytest',

0 commit comments

Comments
 (0)