Registry / serialization / blurhash-python

blurhash-python

JSON →
library1.2.2pypypi✓ verified 84d ago

A Python implementation of the BlurHash algorithm, which encodes an image into a short, blurry placeholder string. Version 1.2.2 is current, with stable but infrequent releases.

pip install blurhash-python
INSTALL
IMPORT
SIG · BLURHASH-PYTHON
B
blurhash-python
serializationpythonv1.2.2
Install
2.5s avg
Import
73ms
Disk
39MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 2.6s
py 3.11
✕ build_error
✓ 2.4s
py 3.12
✕ build_error
✓ 2.2s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 3s
39MB installed
● package 39MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

encode
from blurhash import encode
Official import path from the package.
decode
from blurhash import decode
Official import path for decoding.

Encode an image to a BlurHash string and decode it back to a rough placeholder.

from blurhash import encode, decode from PIL import Image import numpy as np img = Image.open('image.jpg').convert('RGB') arr = np.array(img) blurhash_str = encode(1920, 1080, arr) print(blurhash_str) # Decode back to pixels pixels = decode(blurhash_str, 32, 32) recreated = Image.fromarray(pixels.astype('uint8'), 'RGB') recreated.show()
Debug
Known issues
gotchaThe encode function expects pixel data as a 3D numpy array with shape (height, width, 3) and dtype uint8. Passing a list or incorrect shape will raise a TypeError.
fix
Convert image to a numpy array with dtype uint8 and ensure RGB ordering before calling encode.
affects: all
gotchaThe decode function returns a numpy array of dtype float64, not uint8. Displaying the image requires casting to uint8 and clipping values between 0 and 255.
fix
Use decoded_pixels.astype('uint8') before creating an image object.
affects: all
Errors
Common errors & fixes
TypeError: Argument 'pixels' must be a numpy array with dtype uint8 and shape (height, width, 3)
Passing non-numpy data or incorrect dtype/shape to encode().
fix
Ensure pixels is a numpy array: np.array(Image.open('img.jpg')).astype('uint8') and check shape.
ValueError: Invalid BlurHash: ...
Trying to decode an invalid or corrupted BlurHash string.
fix
Verify the BlurHash string has the correct format (e.g., ~LGFO.?-RM{WB?ofV@WB?ofWBof) and was generated by a compatible encoder.
Upgrade
Version history
1.2.2latest on PyPI · released Jan 24, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
blurhash-python — pip install blurhash-python · libregistry