Skip to main content

A Python package for photo clustering and organization

Project description

PhotoCluster

A Python package for photo clustering and organization.

Installation

From PyPI (when published)

pip install photocluster

Usage

Python API

The package provides a simple function-based API for clustering photos:

from photocluster import photocluster

# Cluster photos with default sensitivity (0.2)
photocluster("/path/to/photos")

# Or specify a custom sensitivity
photocluster("/path/to/photos", sensitivity=0.3)

Parameters:

  • input_dir (str | Path): Directory containing images to cluster
  • sensitivity (float, optional): Clustering sensitivity as a proportion (0.0-1.0). Defaults to 0.2.
    • Lower values (e.g., 0.1-0.2) = stricter clustering
    • Higher values (e.g., 0.5-0.8) = looser clustering

How it works:

  1. Scans the input directory for JPEG images (recursively)
  2. Computes perceptual hashes for each image
  3. Clusters similar images using DBSCAN algorithm
  4. Organizes images into group_0/, group_1/, etc. subdirectories

Example:

from pathlib import Path
from photocluster import photocluster

# Cluster photos with default sensitivity (0.2)
photocluster(Path("~/Pictures/vacation"))

# Or use a custom sensitivity for looser clustering
photocluster(Path("~/Pictures/vacation"), sensitivity=0.25)

# After running, photos will be organized like:
# ~/Pictures/vacation/
#   ├── group_0/
#   │   ├── IMG_001.jpg
#   │   └── IMG_002.jpg
#   ├── group_1/
#   │   ├── IMG_003.jpg
#   │   └── IMG_004.jpg
#   └── ...

Development

Setup development environment

git clone https://github.com/yourusername/photocluster.git
cd photocluster
uv sync --extra dev

Run tests

uv run pytest

Run tests with coverage

uv run pytest --cov=src/photocluster --cov-report=html

Code quality checks

# Format code
uv run ruff format .

# Check code
uv run ruff check .

# Type check
uv run ty check .

License

This project is licensed under the MIT License - see the LICENSE file for details.

Features

  • Perceptual hashing: Uses imagehash library to compute perceptual hashes for similarity detection
  • DBSCAN clustering: Uses scikit-learn's DBSCAN algorithm for robust clustering
  • Multiprocessing: Automatically uses multiple CPU cores for faster processing
  • JPEG support: Currently supports JPEG images (.jpg, .jpeg)
  • In-place organization: Organizes photos into cluster subdirectories within the input directory

Changelog

0.1.0

  • Initial release
  • Basic photo clustering functionality using perceptual hashing
  • Python API with photocluster() function
  • Support for JPEG images
  • Multiprocessing support for faster hash computation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

photocluster-0.1.0.tar.gz (55.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

photocluster-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file photocluster-0.1.0.tar.gz.

File metadata

  • Download URL: photocluster-0.1.0.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for photocluster-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b79a2c5f262f5cd332188b303e05810c52331bd9b4682491349a2079321f2c5
MD5 8502374edd801931fbd2f6f0a0e0af0c
BLAKE2b-256 93339191ff20e1079bbde15d1c3346f896256cfd4feaafb84725ef00acb91d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for photocluster-0.1.0.tar.gz:

Publisher: publish.yml on mdarwish228/photocluster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photocluster-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: photocluster-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for photocluster-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c773cd4502e432d98d6232560e25489d72eb81101f9461dc9adfc43c1db9502
MD5 fb817d3a698cfb0aedea0d0f3dbed583
BLAKE2b-256 a8d113be55b9e9f6a99b0aa6fddbc15079ced17af7a4f1d4bac4d19ca5214e63

See more details on using hashes here.

Provenance

The following attestation bundles were made for photocluster-0.1.0-py3-none-any.whl:

Publisher: publish.yml on mdarwish228/photocluster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page