Skip to content

Commit fd5dd6c

Browse files
authored
Merge pull request #72 from amirreza8002/zstd
use stdlib `zstd` library instead of `pyzstd`
2 parents 4ac8c9b + bee166e commit fd5dd6c

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
12
### Breaking changes
23
- `BackendCommands` and `AsyncBackendCommands` are no longer decorated with `omit_exception`.
34
- added `omit_exception_async` to decorate async operations, instead of using `omit_exception` for both sync and async.
45
- `omit_exception` no longer supports async functions and generators.
56
- added `DecoratedBackendCommands` and `DecoratedAsyncBackendCommands` as commands decorated with `omit_exception` and `omit_exception_async`.
67
- `AsyncValkeyCache` and `ValkeyCache` no longer inherit from `BackendCommands` and `AsyncBackendCommands`, they inherit from `DecoratedBackendCommands` and `DecoratedAsyncBackendCommands` instead.
8+
- stdlib `zstd` is used instead of `pyzstd` (`zstd` is the same as `pyzstd`, but since the package name are different this is counted is breaking change)
79

810
### improvement
911
- removed the undecorator loop from cluster client

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Install 3rd party compression
9191
9292
.. code-block:: console
9393
94-
python -m pip install django-valkey[pyzstd]
94+
python -m pip install django-valkey[zstd] # not need since python 3.14
9595
9696
.. code-block:: console
9797

django_valkey/compressors/zstd.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import pyzstd
2-
1+
import sys
32
from django.conf import settings
43

54
from django_valkey.compressors.base import BaseCompressor
65

6+
if sys.version_info >= (3, 14):
7+
from compression import zstd
8+
else:
9+
from backports import zstd
10+
711

812
class ZStdCompressor(BaseCompressor):
913
"""
@@ -19,7 +23,8 @@ class ZStdCompressor(BaseCompressor):
1923
}
2024
2125
compression parameters:
22-
to set `level_or_option` use either `CACHE_COMPRESS_LEVEL` or `COMPRESS_ZSTD_OPTIONS` in your settings.
26+
to set `level` use `CACHE_COMPRESS_LEVEL`
27+
to set `options` `COMPRESS_ZSTD_OPTIONS` in your settings.
2328
if `COMPRESSION_ZSTD_OPTIONS` is set, level won't be used
2429
2530
to set `minimum size` set `CACHE_COMPRESS_MIN_LENGTH` in your settings, defaults to 15.
@@ -41,15 +46,16 @@ class ZStdCompressor(BaseCompressor):
4146
decomp_zstd_dict = getattr(settings, "DECOMPRESS_ZSTD_DICT", None)
4247

4348
def _compress(self, value: bytes) -> bytes:
44-
return pyzstd.compress(
49+
return zstd.compress(
4550
value,
46-
level_or_option=self.options or self.level or 1,
51+
options=self.options,
52+
level=self.level or 1,
4753
zstd_dict=self.zstd_dict,
4854
)
4955

5056
def _decompress(self, value: bytes) -> bytes:
51-
return pyzstd.decompress(
57+
return zstd.decompress(
5258
value,
5359
zstd_dict=self.decomp_zstd_dict or self.zstd_dict,
54-
option=self.decomp_options or self.options,
60+
options=self.decomp_options or self.options,
5561
)

docs/configure/compressors.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,21 @@ compress_zlib_wbits = 15 # defaults to 15 (NOTE: only available in python 3.11
182182

183183
### Zstd compression
184184

185-
to use zstd compression you need to have the pyzstd library installed
185+
as of `django-valkey` 0.4.0, the zstd library from python stdlib is used instead of `pyzstd`.
186+
187+
if you are using python 3.14 or above, you don't need to install anything,
188+
otherwise, you need to install the `backports.zstd` library:
186189

187190
```shell
188-
pip install django-valkey[pyzstd]
191+
pip install django-valkey[zstd]
192+
# or
193+
pip install django-valkey[pyzstd] # this is for backwards compatibility
189194
```
190195

191-
or simply
196+
or
192197

193198
```shell
194-
pip install pyzstd
199+
pip install backports.zstd
195200
```
196201

197202
then you can configure it as such:
@@ -216,4 +221,4 @@ COMPRESS_ZSTD_DICT = {...}
216221
DECOMPRESS_ZSTD_DICT = {...} # note: if you don't set this, the above one will be used.
217222
```
218223

219-
*NOTE* the values shown here are only examples and *not* best practice or anything.
224+
*NOTE* the values shown here are only examples and *not* best practice or anything.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ lz4 = [
4949
"lz4>=4.3.3",
5050
]
5151
pyzstd = [
52-
"pyzstd>=0.16.2",
52+
"backports.zstd>=1.0.0",
53+
]
54+
zstd = [
55+
"backports.zstd>=1.0.0",
5356
]
5457
msgpack = [
5558
"msgpack>=1.1.0",

0 commit comments

Comments
 (0)