# Batches

## hash\_files

```python
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

```python
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

```python
BatchResult(source: _S, hashes: dict[Algorithm, int] | None, error: PhashError | None)
```

Bases: `Generic[_S]`

The outcome for one item of a batch.

:func:`hash_files` gives `BatchResult[path type]`, :func:`hash_buffers` gives `BatchResult[int]` (the buffer's index).

### source

```python
source: _S
```

The path or buffer index the item was given as.

### hashes

```python
hashes: dict[Algorithm, int] | None
```

The hashes by algorithm, or None if the item failed.

### error

```python
error: PhashError | None
```

Why the item failed, or None.

## ProgressCallback

```python
ProgressCallback = Callable[[int, int], bool | None]
```

Called as `progress(done, total)` after each finished item; returning `False` stops the batch (items not yet started get BatchCancelledError).
