This repository provides a toolset for analyzing, keywording, and tagging photos in an Adobe Lightroom Classic catalog using AI services. By extracting Lightroom previews and sending them to various Large Language Model (LLM) providers (e.g., OpenRouter, Claude, Ollama), it enriches photo metadata with AI-driven insights, including keywords, aesthetic evaluations, and categorization according to a specialized film-photography taxonomy.
Lightroom Classic users commonly face a challenge: large collections of images with incomplete or inconsistent metadata. Manual keyword entry can be time-consuming, and consistent labeling of large photo libraries is difficult. The Lightroom AI Tool addresses these issues by:
- Extracting preview images (or smart previews) from an
.lrcatfile (Lightroom catalog). - Sending images to AI services for analysis (composition, color, subject matter, aesthetic rating, etc.).
- Enhancing the Lightroom catalog with automatically generated keywords, hierarchical tags, aesthetic scores, and more.
This approach helps photographers maintain a well-organized and richly annotated catalog without tedious manual tagging.
-
Preview Extraction
- Automatically locates previews (or uses smart previews/original images if previews are missing).
- Employs multiple search strategies (UUID-based, filename-based, pattern-based, deep search, etc.).
-
AI Integration
- Integrates with multiple AI providers:
- Each provider can parse and return structured JSON containing keywords, tags, and aesthetic evaluations.
-
Metadata Injection
- Writes AI-generated keywords and tags back into the Lightroom catalog database.
- Supports hierarchical keyword creation and advanced film photography taxonomies.
- Optionally updates the caption and rating fields for quick in-Lightroom reference.
-
Checkpointing & Resumability
- Supports resuming interrupted runs through a checkpoint file that tracks processed images.
- Avoids reprocessing images with existing “AI_Processed” keywords (or as recorded in the checkpoint).
-
Parallel Batch Processing
- Can utilize multiple CPU cores to process images in parallel, respecting memory constraints and concurrency.
-
Keyword Consolidation
- Optional step to further unify or consolidate overlapping keywords with LLM-based grouping (e.g., “sunset,” “sunsets,” “setting sun”).
Clone this repository or download a ZIP of it:
git clone https://github.com/yourusername/lightroom-ai-tool.git
cd lightroom-ai-toolIt is recommended to use Python 3.8+ in a virtual environment:
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on WindowsUse pip to install all dependencies:
pip install -r requirements.txtThis installs:
- requests, psutil, pillow, sqlite-related libraries,
- Providers (anthropic, openai, ollama) if needed.
Create or modify config.json in the project root. You can reference the provided config.json or any example config. For instance, if you want to use OpenRouter:
{
"provider": "openrouter",
"openrouter_api_key": "YOUR_OPENROUTER_API_KEY",
"openrouter_model": "anthropic/claude-2",
"openrouter_api_url": "https://openrouter.ai/api/v1/chat/completions",
"openrouter_site_url": "https://example.com",
"openrouter_title": "Lightroom AI Tool",
"max_retries": 3,
"batch_size": 10,
"preview_max_resolution": 1024,
"log_level": "INFO",
"debug_mode": false,
"use_smart_previews": true,
...
}Adjust parameters such as max_workers, memory_limit_mb, deep_search, etc., to suit your system resources.
You have two main ways to run the tool:
-
Command-Line Interface (
cli.py)
Invoked viapython -m lightroom_ai.cli [options]. This script scans your catalog, extracts previews, sends them to AI, and writes back metadata. -
Example Scripts (
examples/Folder)
Theexamples/directory shows typical usage patterns:- example1_basic_usage.py: Basic analysis of a catalog with default settings.
- example2_scan_only.py: Just scans for previews without calling AI.
- example3_filtering.py: Processes only certain images (e.g., matching a filename substring).
- example4_parallel_processing.py: Speeds up analysis via parallel threads.
- example5_ollama_provider.py: Using a local Ollama model.
- example6_database_analysis.py: Debugging your Lightroom catalog structure.
- example7_resuming.py: Demonstrates checkpoint-based resuming of long-running tasks.
- example_keyword_consolidator.py: LLM-based grouping and hierarchical keyword creation.
# Basic usage from the CLI:
python -m lightroom_ai.cli \
/path/to/LightroomCatalog.lrcat \
--config config.json \
--debug \
--batch-size 5 \
--max-workers 2catalog_path: The.lrcatfile of your Lightroom library.--config: The path to yourconfig.json.--debug: Enables debug logs.--batch-size: Number of images to process in each chunk.--max-workers: Parallel worker threads.
cd examples
python example1_basic_usage.py /path/to/LightroomCatalog.lrcatThis:
- Loads
config.jsonat the project root. - Connects to the
.lrcat. - Extracts standard (or smart) previews.
- Sends them to your configured AI provider.
- Inserts new keywords and caption details in the catalog.
If you want to check whether previews exist or need to be built:
python example2_scan_only.py /path/to/LightroomCatalog.lrcat --debugProcess only images whose filenames contain _RAW:
python example3_filtering.py /path/to/LightroomCatalog.lrcat \
--filter "_RAW"An optional keyword consolidation step uses an LLM to cluster synonyms or near-duplicates into canonical forms. It can also create hierarchical keyword structures for cleaner metadata in Lightroom. See:
cd examples
python example_keyword_consolidator.py /path/to/LightroomCatalog.lrcatConfiguration for the consolidation is read from the same or a separate config.json.
git clone https://github.com/yourusername/lightroom-ai-tool.git
cd lightroom-ai-tool
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtWe use pytest for unit tests:
pytest --maxfail=1 --disable-warnings -qTests are located in tests/, covering:
batch_processorfilesystempreview_extractorcli- etc.
Pull requests are welcome. Submit bug fixes, improvements, or new features. Ensure your code is tested and linted. For major changes, open an issue first.
- High concurrency with large catalogs may hit SQLite locking. Consider reducing
max_workersor using a more robust concurrency strategy. - LLM-based analysis depends on the reliability of the AI model’s output. Incomplete or malformed JSON results in partial failures.
- Film Analysis is specialized—some prompts are tuned specifically for film photography taxonomy. Additional customizations may be needed for non-film usage.
- Adobe Lightroom Classic for the
.lrcatdatabase structure. - Anthropic Claude & OpenRouter for the AI endpoints.
- Pillow for image handling, SQLite3 for DB operations, etc.
MIT License
Copyright (c) 2025 Sebastian Ahrens
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Enjoy a more organized Lightroom!
If you have any questions or run into issues, please open an issue on GitHub. Happy photo organizing!