Skip to main content

SplatHash — Python

Python implementation of SplatHash: compress any image to 16 bytes and reconstruct it.

Requirements

  • Python 3.8+
  • Pillow (for loading image files)

Installation

pip install splathash-py

For local development from the repo:

pip install -e src/py

Usage

from splathash import encode, encode_raw, decode

# Encode from a file path
with open("photo.jpg", "rb") as f:
    hash_bytes = encode(f)          # bytes, always 16 bytes

# Or from a file path string directly
hash_bytes = encode("photo.jpg")

# Or from a PIL Image
from PIL import Image
img = Image.open("photo.jpg")
hash_bytes = encode(img)

# Encode from raw RGBA bytes
hash_bytes = encode_raw(rgba_bytes, width, height)

# Decode to 32×32 RGBA
pixels = decode(hash_bytes)         # bytes, 32 * 32 * 4 = 4096 bytes

See example.py for a full working example that encodes a directory of images.

API

encode(source) -> bytes

Encodes an image to a 16-byte SplatHash.

source can be:

  • A file path (str or Path)
  • A file-like object (binary mode)
  • A PIL.Image.Image

Returns bytes of exactly 16 bytes.

encode_raw(rgba: bytes, width: int, height: int) -> bytes

Encodes raw RGBA pixel data. rgba must be width * height * 4 bytes.

Returns bytes of exactly 16 bytes.

decode(hash_bytes: bytes) -> bytes

Decodes a 16-byte SplatHash to a 32×32 RGBA image.

Returns bytes of exactly 32 * 32 * 4 = 4096 bytes (raw RGBA, row-major).

Raises ValueError if hash_bytes is not exactly 16 bytes.

Converting the decoded bytes to an image

from PIL import Image
from splathash import encode, decode

hash_bytes = encode("photo.jpg")
pixels = decode(hash_bytes)

img = Image.frombytes("RGBA", (32, 32), pixels)
img.save("preview.png")

Testing

pip install pytest Pillow
pytest test_splathash.py -v

Or via mise from the repo root:

mise run test:py

How It Works

See ALGORITHM.md for the full technical specification.

Metadata

Release files for splathash-py 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for splathash-py 1.3.0
File Size Uploaded
splathash_py-1.3.0.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for splathash-py 1.3.0
File Interpreter ABI Platform
splathash_py-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / splathash_py-1.3.0.tar.gz

Download URL splathash_py-1.3.0.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eec5a695cd8ad6525fb091bc365e45198d04307ac65632aec9254af2448e30e7
BLAKE2b-256 checksum
How to use checksums
2b9dec7c71eb141c13639c1478001fefffc8e842d94e593543daf88a9494e4ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2026.

Transparency log

Release files / splathash_py-1.3.0-py3-none-any.whl

Download URL splathash_py-1.3.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c5d31a9744b4756c60d0177051485996c4e625edd6338d5705d69444538b851
BLAKE2b-256 checksum
How to use checksums
68ba4e69a326c0daf38940451afc4b7c6f750f49936c8477d3189253faea0e7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page