ImmichSync
Overview
A Python script to intelligently automate syncing a local folder of images (like screenshots) to your Immich server. It safely handles both local network connections and external connections, preventing duplicates and automatically organizing uploaded assets into a designated album.
Features and Working Mechanism
This script operates in the following sequence during a given run:
- Environment Loading: Securely loads credentials and configuration variables, including your API key, target folder, and Immich URLs.
- Network Detection: Pings your local network URL first. If that times out, it seamlessly falls back to your external URL. This is ideal for laptops that frequently switch between home Wi-Fi and outside networks.
- Album Resolution: Queries the Immich API to find the internal ID associated with the album name specified in your configuration.
- Local Deduplication: Consults a local history file (
immich_upload_history.json) to skip files that have already been uploaded previously by the script in past runs. - Server Deduplication & Uploading: Uploads new files along with critical metadata (creation time, modification time). The script properly interprets Immich's API responses to distinguish between a fully new file being created, a soft duplicate that Immich merged, and a hard conflict.
- Album Linking: Any successfully finalized uploads are subsequently linked to the specified target album.
- Status Logging: Every operation is logged both to the console and to a local
immich_backup.logfile, ensuring complete visibility of its operations over time.
Security Considerations
- Authentication: The script authenticates exclusively via the Immich API Key. The key is loaded from a
.envfile that should be excluded from version control to prevent token leakage. - Safe Uploads: It uses a purely additive approach. The script reads files from your local system and posts them to the Immich server; it never deletes or modifies your local files.
- Local Storage: Upload history is saved locally within a JSON file to prevent re-upload attempts, ensuring API rate limits and server resources are respected.
Installation & Usage
Ensure you have Python 3 installed. It is recommended to use a virtual environment.
pip install requests python-dotenv
Create a .env file with the variables SCREENSHOTS_PATH, IMMICH_API_KEY, IMMICH_LOCAL_URL, IMMICH_EXTERNAL_URL, and IMMICH_ALBUM_NAME.
Run via: python uploader_v1.py
View Source: nicx17/ImmichSync