wuti-py-util
A small Python toolkit for internal tools: read and write structured files, validate inputs, touch the filesystem safely, handle common archive formats, and optionally read CSV/Excel.
Requirements: Python >= 3.12. uv is recommended for local development.
Install
pip install wuti-py-util
The core package depends on jsonschema, PyYAML, and zstandard. DataFrame
and Excel features are opt-in:
| Extra | Enables | Install |
|---|---|---|
pandas |
conversion_stats, csv (CsvReader) |
pip install "wuti-py-util[pandas]" |
excel |
excel (ExcelReader), includes pandas |
pip install "wuti-py-util[excel]" |
all |
Everything above | pip install "wuti-py-util[all]" |
What this library is
Core modules: serialization, validation, filesystem, log, archive,
csv / excel (extras), check, plus small helpers (filelist, filehash,
datetime, string, formatting, environment, process).
Frozen (kept for compatibility, no new features): database, web,
dataclass_utils.
Structured files (wuti.util.serialization)
Load and save JSON/YAML files, optionally validating against a
JSON Schema with jsonschema:
from wuti.util.serialization import load_json, save_json
config = load_json("config.json", schema={"type": "object"}) # validated
data = load_json("config.json", as_object=False) # raw dict, no conversion
save_json("out.json", {"key": "value"}) # pretty-printed JSON
load_yaml and save_yaml behave the same way.
Trust boundary
Loading a JSON or YAML file parses data only — unlike pickle, it does not execute code. There is no sandbox either: treat any file you did not create as untrusted input and remember the limits below.
- No validation by default. Without a
schemaargument the document's shape is not checked at all. Pass aschema=(validated withjsonschema) when the source is not fully trusted. - Object mode maps keys to attributes. By default (
as_objectunset and no schema) the loaded document is converted so that every key becomes a Python attribute viasetattr. Untrusted or unusual key names (e.g.__class__,keys) can then collide with the object protocol or produce surprising attribute access. For untrusted data preferas_object=Falseand work with the raw dict. - No size or nesting limits. Parsing has no resource caps: an oversized or
deeply nested document from an untrusted source remains a
denial-of-service risk (deep nesting can raise
RecursionError). - Saving serializes anything.
save_jsonreduces unknown object types via their__dict__; do not pass objects holding secrets or live resources.
YAML is loaded with yaml.safe_load, so YAML-specific code execution tricks
are not applicable.
Formatting (wuti.util.formatting)
Small human-readable helpers:
from wuti.util.formatting import format_bytes_human
format_bytes_human(1536) # '1.50 KB'
format_bytes_human(3 * 1024**3) # '3.00 GB'
import wuti.util.filesystem as filesystem
result = filesystem.prune_empty_dirs("build")
for failure in result.failures:
print(failure) # '/path/to/dir: os_error (denied)'
wuti.util.filesystem also provides path containment helpers:
validate_relative_path rejects absolute paths, NUL bytes, and ..
traversal; resolve_contained_path resolves a relative path under a root
and rejects symlink escape via realpath + commonpath.
Archives (wuti.util.archive)
Create, extract, list, and test common archive formats:
- Archives:
.tar.gz,.tar.xz,.tar.bz2,.tar.lz,.tar.zst,.tgz,.tbz2,.zip,.tar - Single-file compressed data (extract, list, and test only):
.zst,.zstd,.xz,.lz
.tar.lz and .lz are implemented in pure Python on top of the standard
library lzma module (lzip container around a raw LZMA1 stream), so no system
lzip tools are needed. .zst / .tar.zst rely on the zstandard package,
which is a core dependency.
import shutil
import wuti.util.archive as archive
archive.create_archive("my-folder", "backup.tar.zst")
archive.list_archive("backup.tar.zst") # [ArchiveEntry(name=..., size=..., is_dir=...)]
archive.extract_archive("backup.tar.zst", "out-folder")
# Verify integrity without writing anything to disk (full decode).
archive.test_archive("backup.tar.zst")
# Teach shutil.unpack_archive about .zst/.zstd/.lz/.xz single-file data.
archive.register_unpack_formats() # idempotent; safe to call again
shutil.unpack_archive("payload.xz", "payload-folder")
Transactional extraction
uncompress_archive extracts like a build system would: the output is always
one member inside the destination folder (a folder named after the archive's
top-level member, or the archive stem when the members have no single
top-level name; a file named after the stem for single-file data), the
extraction happens in a staging folder and is committed with one atomic
rename, and an already-extracted output is skipped, so repeated runs are
idempotent and a failed run leaves the destination unchanged.
Creation is transactional too: create_archive writes a temporary file in
the destination folder and commits with one atomic rename, so a failed run
never leaves a partial archive and an existing archive stays intact.
target = archive.uncompress_archive("downloads/gettext-0.21.tar.xz", "build")
# -> "build/gettext-0.21"
archive.uncompressed_folderpath("downloads/gettext-0.21.tar.xz", "build")
# -> "build/gettext-0.21" (predicts the path without extracting)
archive.uncompressed_name("downloads/gettext-0.21.tar.xz")
# -> "gettext-0.21" (the member name placed under the destination folder)
Reproducible archives
Pass mtime= to create_archive (or set the standard SOURCE_DATE_EPOCH
environment variable to an integer in [0, 4294967295]; the argument wins when
both are present) to build byte-identical archives from identical content:
member mtimes, member order (name-sorted), uid/gid, and file modes are
normalized, and the gzip container header of .tar.gz/.tgz carries the
epoch instead of the wall clock. Zip timestamps clamp to the DOS floor of
1980-01-01 and carry 2-second granularity, so pick an even epoch when a
byte-identical zip must read back the exact time.
archive.create_archive("my-folder", "release.tar.zst", mtime=1700000000)
# or: SOURCE_DATE_EPOCH=1700000000 create ...
Extraction is defensive: member names are validated before extraction (NUL
bytes, absolute paths, .. parts, and Windows drive roots are rejected), tar
members are extracted with the standard library filter="data" filter, zip
symlinks are rejected, and the extraction result is scanned for links escaping
the destination folder. Total output size is not limited, so extracting
untrusted archives remains a denial-of-service risk.
When a file's name carries no recognized suffix (or a wrong one),
extract_archive, list_archive, and test_archive fall back to
magic-number sniffing: the leading bytes identify zip/gzip/bzip2/xz/lzip/zstd
containers, and a decoded prefix distinguishes a wrapped tar from single-file
data. create_archive still selects the format from the target suffix only.
Zip files written by many tools store UTF-8 member names without the EFS flag
bit (Python then decodes them as cp437, producing mangled non-ASCII names).
list_archive and extract_archive detect this and restore the proper UTF-8
spelling when the bytes round-trip cleanly.
Development
Development dependencies (pytest, coverage, ruff, mypy, hatchling, etc.) live in
[dependency-groups].dev in pyproject.toml — not as a published PyPI extra.
Use uv from the repository root:
uv sync --group dev
Run checks through that environment:
uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run mypy
If you intentionally use an already-active shared venv, use --inexact so uv
does not remove packages installed manually with uv pip install:
uv sync --active --inexact --group dev
uv run --active pytest
uv run --active ruff check .
uv run --active ruff format --check .
uv run --active mypy
Test data (tests/data)
Integration tests use fixtures from the
wuti-py-testdata Git submodule
(Git LFS). After cloning, initialize the submodule and pull LFS objects
(Git LFS must be installed):
git submodule update --init
git -C tests/data lfs pull
CI runs the same LFS pull after checkout with submodules: true.
Light fixtures live under tests/data/samples/ (sample.json, sample.yaml,
filelist.lst). ABS and GEO datasets stay in their own folders. Path constants
in tests/testdata.py (SAMPLE_JSON, SAMPLE_YAML, SAMPLE_FILELIST, …)
point at that layout.
tests/testdata.py sets HAS_TEST_DATA when tests/data exists and is
non-empty. That check is intentionally shallow: it does not verify that
files are real payloads rather than LFS pointer
files. If you only
run git submodule update --init without lfs pull, the directory still
contains pointer stubs, HAS_TEST_DATA is true, and pytest will run those
tests instead of skipping them — then fail when code reads corrupt or tiny
pointer content. Any future “do we have test data?” logic should not rely on
presence alone; detect LFS pointers or validate expected file sizes/checksums.
Tests marked with @requires_test_data skip when the submodule is missing or
empty; they do not skip on unfetched LFS.
Build and publish
Version comes from __version__ in src/wuti/util/__init__.py. The GitHub
Release workflow requires the git tag (vX.Y.Z) to match that version. PyPI
rejects duplicate versions.
uv build
uv pip install dist/wuti_py_util-<version>.tar.gz
Publish to PyPI (https://upload.pypi.org/legacy/) with a PyPI API
token via UV_PUBLISH_TOKEN or
--token:
uv publish
Metadata
Release files for wuti-py-util 0.8.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wuti_py_util-0.8.4.tar.gz | 64.0 kB | Without provenance | Details for wuti_py_util-0.8.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wuti_py_util-0.8.4-py3-none-any.whl | Python 3 | none | any | Details for wuti_py_util-0.8.4-py3-none-any.whl |
Total release size: 138.8 kB
Release files / wuti_py_util-0.8.4.tar.gz
| Download URL | wuti_py_util-0.8.4.tar.gz |
|---|---|
| Size | 64.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
580744019f086fc17870ce247da71676bb3f2a3bd58df8c3f788a92abf05d8dd
|
|
BLAKE2b-256 checksum How to use checksums |
652c9e50b92d71cd02d4a317551a3ce9a2e222ea9f85129a8b6fc148670fb233
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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 / wuti_py_util-0.8.4-py3-none-any.whl
| Download URL | wuti_py_util-0.8.4-py3-none-any.whl |
|---|---|
| Size | 74.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27fd297ed6e66b5d9d9e790681d1b0a3d5cdbd534a016f8025634ea9a4195539
|
|
BLAKE2b-256 checksum How to use checksums |
94b567902443925a86390e65ad188d6604361d4cc2419a6ab96b4cef132be851
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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}
|
Security for wuti-py-util 0.8.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.