kompress lets you transparently decompress common archive formats while using pathlib.Path objects.
It attempts to keep the API as close to pathlib, but things may not be perfect yet
The common case for this is:
- You have a compressed file that when decompressed contains some text
- You have a function (perhaps from another library, that you don't control), that knows how to take a
pathlib.Pathobject and call.read()or.read_text()on it
Without wrapping the function or adding logic to let it read from compressed files, this lets you do the following:
from pathlib import Path
from kompress import CPath, is_compressed
def char_count(path: Path) -> int:
# here, if a CPath is passed, it decompresses and returns a string
return len(path.read_text())
inp = input("Enter a file to process: ") # file came from user
char_count(CPath(inp))
This currently supports these archive formats:
.xz.zip.zst.tar.gz.gz.zstd(sincepython3.14, on older version usepip install 'kompress[zstd]').lz4(pip install 'kompress[lz4]')
If it doesn't recognize the filetype, it will just call pathlib.Path.open, reading it like a regular file.
Originally discussed in this HPI issue
Installing
pip install kompress
Metadata
Release files for kompress 0.3.20260707
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kompress-0.3.20260707.tar.gz | 22.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kompress-0.3.20260707-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.1 kB
Release files / kompress-0.3.20260707.tar.gz
| Download URL | kompress-0.3.20260707.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7896945d671077cfb0e26b5e85b3d0e1680c1cdeacc42b0f23b329f17656e34
|
|
BLAKE2b-256 checksum How to use checksums |
418759d716766236887d24b46f846914e4237d41848965aa48f6f40c786f6707
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / kompress-0.3.20260707-py3-none-any.whl
| Download URL | kompress-0.3.20260707-py3-none-any.whl |
|---|---|
| Size | 18.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48a5446ab36335660fa54f24980cfefe3681cdbf750dfdd6cca8e815657f1c27
|
|
BLAKE2b-256 checksum How to use checksums |
951df381e7b4c25adae4ecceee77f4a4f0a31ad5726c808f764cd45b938afa94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|