Batches¶
hash_files ¶
hash_files(paths: Iterable[_P], algorithms: _Algorithms = (PHASH,), *, config: Config | None = None, threads: int = 0, progress: ProgressCallback | None = None) -> list[BatchResult[_P]]
Hash many image files on libphash's pool of threads.
Only the 64-bit algorithms (aHash, dHash, pHash, wHash) can be batched. A failed
file does not stop the batch: its result carries the error. threads=0 uses one
thread per usable CPU, 1 runs on the calling thread. Each worker holds one
decoded image at a time, so peak memory grows with the thread count (bound it with
threads or Config.max_pixels). Ctrl+C stops the batch and raises
KeyboardInterrupt.
hash_buffers ¶
hash_buffers(buffers: Iterable[bytes | bytearray | memoryview], algorithms: _Algorithms = (PHASH,), *, config: Config | None = None, threads: int = 0, progress: ProgressCallback | None = None) -> list[BatchResult[int]]
Hash many encoded images held in memory; see :func:hash_files.
BatchResult.source is the buffer's index. The buffers must not change while the
call runs.
BatchResult
dataclass
¶
BatchResult(source: _S, hashes: dict[Algorithm, int] | None, error: PhashError | None)
ProgressCallback
module-attribute
¶
Called as progress(done, total) after each finished item; returning False
stops the batch (items not yet started get BatchCancelledError).