Skip to main content

Fast ThumbHash encode/decode – Rust-powered Python bindings

Project description

thumbleweed

Fast ThumbHash encode/decode for Python — Rust-powered, zero mandatory dependencies.

A drop-in replacement for thumbhash and fast-thumbhash, built with PyO3 and maturin.

  • ✅ Python 3.10 – 3.14 (including free-threaded 3.13t / 3.14t)
  • ✅ Pillow > 11 integration (optional)
  • ✅ Typed (py.typed + .pyi stubs)
  • ✅ Pure-Rust core — no C extensions, no NumPy required

Installation

pip install thumbleweed
# with Pillow helpers:
pip install "thumbleweed[pillow]"

Both import thumbhash and import thumbleweed work.


Quick-start

Raw RGBA bytes

import thumbhash as th

# Encode — rgba_bytes must be bytes/bytearray of length w*h*4 (R G B A, non-premultiplied)
hash_bytes: bytes = th.encode(w, h, rgba_bytes)

# Decode
w_out, h_out, rgba_out = th.decode(hash_bytes)

# Helpers
r, g, b, a = th.average_rgba(hash_bytes)           # dominant colour [0, 1]
ratio = th.approximate_aspect_ratio(hash_bytes)     # width / height

Pillow images

from PIL import Image
import thumbhash as th

img = Image.open("photo.jpg")

hash_bytes = th.encode_image(img)                   # any mode, any size
placeholder = th.decode_image(hash_bytes)           # → RGBA Image, ≈32 px
placeholder.save("placeholder.png")

encode_image automatically converts to RGBA and shrinks the longest side to ≤ 100 px (the algorithm's hard limit).


API reference

Function Description
encode(w, h, rgba) → bytes Encode raw RGBA bytes → ThumbHash
decode(hash) → (w, h, rgba) Decode ThumbHash → raw RGBA bytes
average_rgba(hash) → (r,g,b,a) Dominant colour in [0, 1]
approximate_aspect_ratio(hash) → float Width / height of the original image
encode_image(img) → bytes Encode a Pillow Image (requires Pillow)
decode_image(hash) → Image Decode a ThumbHash to a Pillow Image (requires Pillow)

Building from source

git clone https://github.com/New-Elysium/thumbleweed.git
cd thumbleweed
python3 -m venv .venv && . .venv/bin/activate
pip install "maturin>=1.10,<2" "Pillow>12" pytest
maturin develop --release
pytest -v

Licence

MIT — see LICENCE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thumbleweed-0.1.2.tar.gz (274.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

thumbleweed-0.1.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.3 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.5 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

thumbleweed-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (202.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file thumbleweed-0.1.2.tar.gz.

File metadata

  • Download URL: thumbleweed-0.1.2.tar.gz
  • Upload date:
  • Size: 274.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for thumbleweed-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7e14ea91eed52c2dd8f518b7e58ba1593bc7067734536c2621aa2016a73d7be6
MD5 5f00ccc952b595600b76a16ae012b697
BLAKE2b-256 4723a2dd74fee652fafec8522e03dddc54589b889b2d78a3d1b15033689cd96f

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca4ec81516e444e38755a5da7a360bbc505ec208a3c9952fd8edcdff9b393036
MD5 b08018c37472fbbdc305727aea3c06f4
BLAKE2b-256 d148c2c0335c72cb64a0969c6e6d4b7389d499a43e8d0a1548e743d93e10048e

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 672d7a6afa6e28502ccc1b4216e75e925b3241e7635c7630beb6e62d9519421f
MD5 5e43f549e91030c1e37032dd6c118716
BLAKE2b-256 a55ec9d5df6816ef7d17a0641bafbb1214e3f696b73ad864efd8c2eb93a5b182

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 267e09476efb5f553b959a12ee8b290b31310a0907c99da735b5f476e05aa63c
MD5 3a16323846e46b8b76e25b6f1c08f31d
BLAKE2b-256 484568814a3b9656e23cb38deb50f9816b3ad6386af9ffec8a57a5bfbe4cc5db

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56fe3ee3bc53b8c7175c465d041f050906aecb42ab6e871aeb0628374c64467d
MD5 1868e45fee18abebc2c15b87463d43c3
BLAKE2b-256 d31c50009f3324e3ae0a27c252ebe25f0661dd626e698a2a07772f7e8c815dd7

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3c8715f2d82ee78abf567e4485c3d0b617fc86fedfa6e906deadc37d6006e485
MD5 5ef3245dd1aea03ae7db977118baf5a7
BLAKE2b-256 a09190121f8a472a7ea92cd1d9ef5ce9128a1c408338640df6a524554d184d6b

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 027c26b0f906b5b5dd751d37d2c4b62318d9eb1eec413aabe33ee231460b4248
MD5 2bc6eb6e7ea4358d0c8c71285210c2a6
BLAKE2b-256 f9b8279e09d301f4ada4c8c669e34067298bc2d7b89f4e31056ff7638424077f

See more details on using hashes here.

File details

Details for the file thumbleweed-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for thumbleweed-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1aa5d033911baef921084764eeaaea4c04d872c2d90ec24896cf4e3246999e34
MD5 7c58f64835a630c1a2a38fccdebe29cc
BLAKE2b-256 f0c1ab7c562016c0838f3acc74d0a30df8e5a5452f94488e7286ceb52ad5a940

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page