YAPF/bindings/python
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nexoniarz d7f494a0c9 Language bindings, KDE thumbnails, yapf compare, in-memory encoding
- yapf_encode() / yapf_free_buffer(): encode to memory; yapf_save uses it
- yapf.c also compiles as C++
- `yapf compare`: size and decode speed of the original format vs YAPF,
  with a lossless check
- bindings with tested examples: C++ (header-only), C# (P/Invoke),
  Rust (crate, builds the C code), Go (cgo), Java (FFM API, Java 22+),
  Zig (@cImport), LuaJIT (FFI), TypeScript types for the JS port;
  Python now encodes in memory
- docs/LANGUAGES.md and examples/ with measured results
- KDE Dolphin thumbnail plugin (KF6, CMake)
- README: honest status for Photoshop / VS Code / Figma (not run in the
  apps yet) and macOS (cross-compiled only), platform table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 14:39:56 +02:00
..
example.py Language bindings, KDE thumbnails, yapf compare, in-memory encoding 2026-10-03 14:39:56 +02:00
README.md Language bindings, KDE thumbnails, yapf compare, in-memory encoding 2026-10-03 14:39:56 +02:00
yapf.py Language bindings, KDE thumbnails, yapf compare, in-memory encoding 2026-10-03 14:39:56 +02:00

yapf.py — YAPF in Python

import yapf

img = yapf.load("texture.yapf")        # or yapf.decode(data)
print(img.width, img.height, img.channels, img.mip_levels)
img.pixels                             # bytes, rows top to bottom

yapf.save("copy.yapf", img)            # or yapf.encode(img) -> bytes
yapf.save("new.yapf", yapf.Image(w, h, 4, rgba_bytes))

It uses the C library through ctypes when it finds one:

  1. the file named by the YAPF_LIBRARY environment variable,
  2. libyapf.so / libyapf.dylib / yapf.dll next to yapf.py, or in lib/<platform>/ beside it (e.g. lib/windows-x64/yapf.dll),
  3. the system library path (sudo make install installs one).

Without the library it falls back to a pure-Python decoder that needs numpy (decoding only; about 1.4 s for a 4K image). yapf.backend() tells you which one is in use.

Example: YAPF_LIBRARY=../../build/libyapf.so python3 example.py ../../other/YAPF.YAPF