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.
This script operates in the following sequence during a given run:
- Environment Loading: It securely loads credentials and configuration variables, including your API key, target folder, and Immich URLs.
- Network Detection: It 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: It queries the Immich API to find the internal ID associated with the album name specified in your configuration.
- Local Deduplication: It 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 and Uploading: It 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.
- 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.
- Clone this repository or download the script files to your local machine.
- Ensure you have Python 3 installed.
- It is recommended to use a virtual environment:
python -m venv .venv source .venv/bin/activate - Install the required dependencies:
pip install requests python-dotenv
- Create a
.envfile in the same directory as the script based on this structure:SCREENSHOTS_PATH="/path/to/your/folder" IMMICH_API_KEY="your_api_key_here" IMMICH_LOCAL_URL="http://192.168.x.x:2283" IMMICH_EXTERNAL_URL="https://immich.yourdomain.com" IMMICH_ALBUM_NAME="Your Target Album"
Once configured, run the script via Python:
python uploader_v1.pyFor continuous backups, you can schedule this script to run periodically using a cron job (Linux/macOS) or Task Scheduler (Windows).
This project is licensed under the GNU General Public License v3.0.