Skip to main content

blurhash-python

import blurhash
import PIL.Image
import numpy

PIL.Image.open("cool_cat_small.jpg")
# Result:

A picture of a cool cat.

blurhash.encode(numpy.array(PIL.Image.open("cool_cat_small.jpg").convert("RGB")))
# Result: 'UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH'

PIL.Image.fromarray(numpy.array(blurhash.decode('UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH', 128, 128)).astype('uint8'))
# Result:

Blurhash example output: A blurred cool cat.

Blurhash is an algorithm that lets you transform image data into a small text representation of a blurred version of the image. This is useful since this small textual representation can be included when sending objects that may have images attached around, which then can be used to quickly create a placeholder for images that are still loading or that should be hidden behind a content warning.

This library contains a pure-python implementation of the blurhash algorithm, closely following the original swift implementation by Dag Ågren. The module has no dependencies (the unit tests require PIL and numpy). You can install it via pip:

$ pip3 install blurhash

It exports five functions:

  • "encode" and "decode" do the actual en- and decoding of blurhash strings
  • "components" returns the number of components x- and y components of a blurhash
  • "srgb_to_linear" and "linear_to_srgb" are colour space conversion helpers

Have a look at example.py for an example of how to use all of these working together.

Documentation for each function:

blurhash.encode(image, components_x = 4, components_y = 4, linear = False):
"""
Calculates the blurhash for an image using the given x and y component counts.

Image should be a 3-dimensional array, with the first dimension being y, the second
being x, and the third being the three rgb components that are assumed to be 0-255 
srgb integers (incidentally, this is the format you will get from a PIL RGB image).

You can also pass in already linear data - to do this, set linear to True. This is
useful if you want to encode a version of your image resized to a smaller size (which
you should ideally do in linear colour).
"""

blurhash.decode(blurhash, width, height, punch = 1.0, linear = False)
"""
Decodes the given blurhash to an image of the specified size.
    
Returns the resulting image a list of lists of 3-value sRGB 8 bit integer
lists. Set linear to True if you would prefer to get linear floating point 
RGB back.

The punch parameter can be used to de- or increase the contrast of the
resulting image.

As per the original implementation it is suggested to only decode
to a relatively small size and then scale the result up, as it
basically looks the same anyways.
"""

blurhash.srgb_to_linear(value):
"""
srgb 0-255 integer to linear 0.0-1.0 floating point conversion.
"""
    
blurhash.linear_to_srgb(value):
"""
linear 0.0-1.0 floating point to srgb 0-255 integer conversion.
"""

Release files for blurhash 1.1.5

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

Source distribution (sdist)

Source distribution for blurhash 1.1.5
File Size Uploaded
blurhash-1.1.5.tar.gz 50.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blurhash 1.1.5
File Interpreter ABI Platform
blurhash-1.1.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 57.5 kB

Release files / blurhash-1.1.5.tar.gz

Download URL blurhash-1.1.5.tar.gz
Size 50.9 kB
Tags Source
SHA-256 checksum
How to use checksums
181e1484b6a8ab5cff0ef37739150c566f4a72f2ab0dcb79660b6cee69c137a9
BLAKE2b-256 checksum
How to use checksums
24f39e636182d0e6b3f6b7879242f7f8add78238a159e8087ec39941f5d65af7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 17, 2025.

Transparency log

Release files / blurhash-1.1.5-py2.py3-none-any.whl

Download URL blurhash-1.1.5-py2.py3-none-any.whl
Size 6.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
96a8686e8b9fced1676550b814e59256214e2d4033202b16c91271ed4d317fec
BLAKE2b-256 checksum
How to use checksums
bddccadbf64b335a2ee0f31a84d05f34551c2199caa6f639a90c9157b564d0d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 17, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.0

2 release files

1.0.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