Phim
A Python library to detect perceptual image duplicates.
About perceptual hashes
Perceptual hashing algorithms are efficient at detecting near duplicate images which arise, e.g. due to different resolutions or compression rates. These algorithms work by computing a hash for each image. This hash works as a sort of fingerprint, and similar images should have similar hashes. In particular, the hashes are binary vectors, and we count the number of differing entries (or bits) to measure image similarity.
Consider the following simplified example.
There are two images: img1 and img2 with these hashes:
img1: 10010111
img2: 10110100
We can represent those bit-vectors using two bytes: 151 for img1 and 180 for img2.
In reality, the bit-vectors are longer, so we get additional bytes, which are stored as an array of 8-bit unsigned integers.
However, they differ at three places
img1: 10010111
img2: 10110100
difference: --x---xx
so their Hamming distance is three.
Perceptual hashing algorithms
Phim supports two hashing algorithmns: pHash and PDQ-hash. They are both based on the discrete cosine transform (DCT) and have similar properties. The main difference is their resolution and which parts of the DCT they use. The PDQ-hash is a 256-bit perceptual hash algorithm made by Meta aiming for exchanging threat information between companies. The pHash algorithm is very similar, but it's a bit older and has only 64 bits.
Another difference between the PDQ-hash and the pHash is that the PDQ-hash computes the hash for all eight possible 90 degree rotation/mirror combinations by smartly transforming the DCT. The same trick could, in theory, be applied during the pHash calculations as well, but it is in general not supported by most implementations (including this one).
Phim comes with an efficient pHash implementation and provides a unified interface to the PDQ-hash as well.
However, for the PDQ-hash you also need to install the pdqhash Python library, which binds the reference C++ implementation of the PDQ-hash made by the Facebook Threat Exchange.
Example
Simple pHash example
import phim
import PIL.Image as Image
img1 = Image.open(...)
img2 = Image.open(...)
phash1 = phim.compute_phash(img1)
phash2 = phim.compute_phash(img2)
differing_bits = phim.compute_hamming_distance(phash1, phash2)
print(f"There are {differing_bits} differing bits between the two pHashes")
Simple PDQ-hash example
import phim
import PIL.Image as Image
img1 = Image.open(...)
img2 = Image.open(...)
pdq_hash_combos1, quality1 = phim.compute_pdq_hashes(img1.convert("RGB"))
pdq_hash_combos2, quality2 = phim.compute_pdq_hashes(img2.convert("RGB"))
differing_bits = phim.compute_hamming_distances(pdq_hash_combos1[0], pdq_hash_combos2)
print(f"There are {min(differing_bits)} differing bits between the two PDQ-hashes")
More intricate example
import phim
import PIL.Image as Image
import numpy as np
image_paths = ...
images = [Image.open(p) for p in image_paths]
query_img = Image.open(...)
phash = phim.compute_phash(query_img)
phashes = np.stack([phim.compute_phash(img) for img in images])
differing_bits = phim.compute_hamming_distances(phash, phashes)
most_similar_index = differing_bits.argmin()
print(f"The most similar image is {image_paths[most_similar_index]}")
Metadata
Release files for phim 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 3.8 MB
Release files / phim-0.0.6-cp311-abi3-win_amd64.whl
| Download URL | phim-0.0.6-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 149.2 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6586b6a39e9f698279f6a1b02f5ceef41909e814dc43f4fb56241d8c011993cb
|
|
BLAKE2b-256 checksum How to use checksums |
edf12eb513f0533a5bfbeaa0c45369a6389f883e5dbafa81ffb7bc93d36e6b4e
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | phim-0.0.6-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 496.2 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
063b22df162543e00c3234e997b2fb893ead77166821f003ba712d6f085dd3c9
|
|
BLAKE2b-256 checksum How to use checksums |
399f71f0af387b79ca0a5945184fd5f61047411fca958abdb18926b1fbe03725
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-musllinux_1_2_i686.whl
| Download URL | phim-0.0.6-cp311-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 529.5 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
bc9ea6d40b279b20757782a2bbffdb2e703dcecada9d46d76e6ba92ec5939b40
|
|
BLAKE2b-256 checksum How to use checksums |
9dec4184d2531a308a7a1f3a49892361d630d4d98e529c69eb65bbb80c22961a
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 295.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
69bfef6c48fcf395380ee3f3c96ef7fecfc508daf6929f9d15b73bee04db4644
|
|
BLAKE2b-256 checksum How to use checksums |
d07876f15a7099c46dad97a0deb687f3a6e341ecfe22011e73b2d7238325698f
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 309.9 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
93f31e1f1c081b6a9802f061d903c6e411985b4879d8e01815dc35f2cdec168e
|
|
BLAKE2b-256 checksum How to use checksums |
ea122c2c5feb5ad75c153c8617ad3c846ff720101d68b4217320913e98d44a08
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 404.8 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
fd7d65594283a850ddae81d6eea1b9e15b36de4e15c921a118d1d90080c28d33
|
|
BLAKE2b-256 checksum How to use checksums |
c08844483458d2cd4cae69a7f42110b1fb33c4fa27da8e06b2da763e4f56f793
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 295.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
115b7787e96fa26dc5ac948e0420308a82e517928078d62bcf3f4a7ceba8182d
|
|
BLAKE2b-256 checksum How to use checksums |
bcac9ec82e7be489e777471ab2f819107c448ef58e92b7d364f77ff95ff826d6
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 288.1 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
50dce79f85783d92f34df0d2a0fbbabd5ddd3ea99554f19ba20c7ed9364af3c2
|
|
BLAKE2b-256 checksum How to use checksums |
65d611f6786bbada03bda88abe009cdf80805b15ebaf9613b04a956dc4cb55b2
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | phim-0.0.6-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 311.8 kB |
| Tags | CPython 3.11 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
96b3500173cbc6445e71491653662bf9a8c28e2064488b9301dda96970a94c30
|
|
BLAKE2b-256 checksum How to use checksums |
379c2a5f40d489f778e66fa9bb139789729aec87956ecac6c6ac165cda7e128f
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | phim-0.0.6-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 258.1 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d374d03bf676025d4d5ba6b64f34b1713d7b3d71b05eb372f7d90303adbdb82a
|
|
BLAKE2b-256 checksum How to use checksums |
9d52c011ac112d30a2e68edc265b51e670a9331f184b40a6615dbb08bd63f19e
|
| 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 Apr 25, 2026.
Transparency logRelease files / phim-0.0.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | phim-0.0.6-cp311-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 503.3 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
401619631b6df86a26510303c2281d75a869c49bb5754f7faa658862a817d6b2
|
|
BLAKE2b-256 checksum How to use checksums |
50547cf496b5f725c0a733e6d68f8f613d5fef2abf9c241b1f4d29a990becfad
|
| 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 Apr 25, 2026.
Transparency log