The environment variable handling for IMMICH_API_KEY has been updated to remove strict requirement checks. This change improves setup flexibility by allowing services to start even if the API key is not explicitly defined in the .env file, assuming a default or alternative mechanism handles missing values gracefully. - Removes mandatory check for IMMICH_API_KEY environment variable
Immich external library to albums
This script creates Immich albums from the directory names in an external library and adds the corresponding assets to them. It does not move or modify the original files.
For example, with:
EXTERNAL_ROOT=/mnt/nextcloud-photos
ALBUM_MODE=root
the asset:
/mnt/nextcloud-photos/Korea_2016_07_08/photo.jpg
is added to an album named Korea_2016_07_08. Files in nested directories
below Korea_2016_07_08 are added to the same album.
Configuration
Required environment variables:
IMMICH_URL: Immich server URL, for examplehttp://immich-server:2283IMMICH_API_KEY: API key withasset.read,album.read,album.create, andalbumAsset.createpermissionsIMMICH_LIBRARY_ID: ID of the external Immich library
Optional environment variables:
EXTERNAL_ROOT: Path stored in Immich'soriginalPath; defaults to/mnt/nextcloud-photosALBUM_MODE:root(default),leaf, orrelativeALBUM_SEPARATOR: Separator forrelativemode; defaults to-PAGE_SIZE: Immich search page size; defaults to1000DRY_RUN: Set totrueto log planned work without changing albums
Run the script after Immich has scanned the external library:
uv run python src/main.py
Docker Compose
Copy the example configuration and insert your Immich API key and external library ID:
cp .env.example .env
docker compose up --build
The example starts with DRY_RUN=true. Check the output, then set
DRY_RUN=false in .env and run docker compose up again.
When Immich publishes port 2283 on the same Docker host, use:
IMMICH_URL=http://host.docker.internal:2283
For an Immich server on another machine, use its normal HTTP(S) URL instead.
The photo directory does not need to be mounted into this container:
EXTERNAL_ROOT is matched against the path recorded in Immich's
originalPath field.
The Compose service performs one synchronization and then exits. Run it after an external-library scan, or invoke it regularly with a scheduler such as cron.
The script only adds missing assets. It never removes assets from albums and never deletes albums.