Created
August 27, 2025 21:06
-
-
Save hakanu/ff51ea5620c8a1603afdb1a339018c19 to your computer and use it in GitHub Desktop.
Immich bulk delete by multiple ids
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from datetime import datetime | |
| # === CONFIG === | |
| IMMICH_URL = "http://localhost:2283/api" | |
| API_KEY = os.environ.get("IMMICH_API_KEY") | |
| DATE_AFTER = "2025-08-25T00:00:00.000Z" | |
| DATE_BEFORE = "2025-08-29T00:00:00.000Z" | |
| HEADERS = { | |
| "x-api-key": API_KEY, | |
| "Accept": "application/json", | |
| "Content-Type": "application/json", | |
| } | |
| # First two lines are from postgres output, useless. | |
| # Also the lines have single space as prefix, need to eliminate that too. | |
| to_delete = [x.strip() for x in open('asset_ids_to_be_deleted.txt', 'r').read().splitlines()[2:]] | |
| print('to_delete', to_delete[:10]) | |
| print(f"Found {len(to_delete)} assets to delete.") | |
| if not to_delete: | |
| exit("Nothing to delete. Check your date range.") | |
| # === STEP 3: Delete in batches (API limit: 100 per call) === | |
| # I can only make 1 work, any larger number was not deleting fully. | |
| #BATCH_SIZE = 100 | |
| BATCH_SIZE = 1 | |
| for i in range(0, len(to_delete), BATCH_SIZE): | |
| batch = to_delete[i:i+BATCH_SIZE] | |
| print(f"Deleting batch {i//BATCH_SIZE+1} ({len(batch)} items)...") | |
| # print('batch', batch) | |
| del_resp = requests.delete( | |
| f"{IMMICH_URL}/assets", | |
| headers=HEADERS, | |
| json={"ids": batch, "force": True} | |
| ) | |
| print('del_resp', del_resp) | |
| if del_resp.status_code == 200: | |
| print("Batch deleted successfully.") | |
| else: | |
| print("Error:", del_resp.status_code, del_resp.text) | |
| print("✅ Deletion complete!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment