immich-icloud-sync 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- immich_icloud_sync-0.1.1/LICENSE +21 -0
- immich_icloud_sync-0.1.1/PKG-INFO +137 -0
- immich_icloud_sync-0.1.1/README.md +117 -0
- immich_icloud_sync-0.1.1/pyproject.toml +129 -0
- immich_icloud_sync-0.1.1/pyproject.toml.orig +113 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/__init__.py +3 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/__main__.py +5 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/api/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/api/server.py +141 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/api/views.py +228 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/cli.py +434 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/config/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/config/load.py +85 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/config/model.py +305 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/config/secrets.py +94 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/config/since.py +59 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/daemon/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/daemon/runner.py +83 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/daemon/schedule.py +51 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/daemon/service.py +110 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/adapter.py +170 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/cloudkit.py +171 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/fingerprint.py +25 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/model.py +119 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/port.py +50 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/records.py +229 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/icloud/session.py +199 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/immich/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/immich/client.py +199 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/immich/errors.py +17 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/immich/models.py +69 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/immich/preflight.py +138 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/notify/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/notify/webhooks.py +138 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/deletions.py +123 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/flags.py +54 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/imports.py +164 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/metadata.py +30 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/owners.py +49 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/rules/publish.py +29 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/state/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/state/errors.py +2 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/state/migrations.py +127 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/state/records.py +54 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/state/store.py +401 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/__init__.py +0 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/apply.py +163 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/deleting.py +75 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/journal.py +46 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/lock.py +25 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/one_pass.py +252 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/options.py +60 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/publishing.py +60 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/render.py +174 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/report.py +92 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/sidecar.py +46 -0
- immich_icloud_sync-0.1.1/src/immich_icloud_sync/sync/steps.py +109 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Dias
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: immich-icloud-sync
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: One-way sync from iCloud Photos to Immich and Noodle Gallery, built around the iCloud Shared Photo Library.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
12
|
+
Requires-Dist: httpx>=0.28
|
|
13
|
+
Requires-Dist: pydantic>=2.11
|
|
14
|
+
Requires-Dist: pyicloud>=2026.11.2,<2027
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Project-URL: Source, https://github.com/defts/immich-icloud-sync
|
|
17
|
+
Project-URL: Documentation, https://github.com/defts/immich-icloud-sync/tree/main/docs
|
|
18
|
+
Project-URL: Issues, https://github.com/defts/immich-icloud-sync/issues
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# immich-icloud-sync
|
|
22
|
+
|
|
23
|
+
One-way sync from iCloud Photos to [Immich](https://immich.app) and
|
|
24
|
+
[Noodle Gallery](https://github.com/open-noodle/gallery), built around the iCloud Shared Photo
|
|
25
|
+
Library: every photo lands in the account of the person who took it, and shared photos are also
|
|
26
|
+
published to a shared space or album.
|
|
27
|
+
|
|
28
|
+
```mermaid
|
|
29
|
+
flowchart LR
|
|
30
|
+
A[Alice's library] --> T[immich-icloud-sync]
|
|
31
|
+
B[Bob's library] --> T
|
|
32
|
+
S[Shared Library] --> T
|
|
33
|
+
T --> UA[Alice in Immich]
|
|
34
|
+
T --> UB[Bob in Immich]
|
|
35
|
+
T --> D[Family space<br>or shared album]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
It runs on your server, reads iCloud through the same web service as icloud.com, and never writes
|
|
39
|
+
to iCloud.
|
|
40
|
+
|
|
41
|
+
**Status:** pre-release. Personal libraries and the Shared Library are imported and published;
|
|
42
|
+
edits, favourites, hiding and, if you turn them on, deletions follow Photos. See
|
|
43
|
+
[what is planned](docs/design.md#13-milestones).
|
|
44
|
+
|
|
45
|
+
## What it does
|
|
46
|
+
|
|
47
|
+
- **Each photo to its owner.** A personal library goes to its account; a Shared Library photo goes
|
|
48
|
+
to whoever put it there, or to the owner of the camera that took it.
|
|
49
|
+
- **Shared photos, shared.** Shared Library photos are also added to a Noodle Gallery space or an
|
|
50
|
+
Immich album, once: one removed from there stays removed.
|
|
51
|
+
- **As Photos shows them.** Originals, the edited version stacked on top (a newer edit goes on
|
|
52
|
+
top, an edit undone puts the original back there, old edits stay below), Live Photo videos; the
|
|
53
|
+
date and time, the place and the caption as Photos has them, corrections included. Hidden photos
|
|
54
|
+
go to the owner's locked folder.
|
|
55
|
+
- **Favourites follow Photos.** A favourite set or removed in Photos is applied in Immich; one set
|
|
56
|
+
in Immich stays. A photo hidden later goes to the locked folder.
|
|
57
|
+
- **Deletions, if you want them.** Off by default. Turned on, a photo deleted in Photos goes to
|
|
58
|
+
the Immich trash, and comes back if it is taken out of Recently Deleted, under guards: a window,
|
|
59
|
+
a daily brake, a delay for personal libraries.
|
|
60
|
+
- **Incremental.** A pass reads what changed since the previous one; a weekly pass reads everything
|
|
61
|
+
again. A pass stopped anywhere is finished by the next, without duplicates.
|
|
62
|
+
- **Unattended.** A daemon with an HTTP API, Prometheus metrics, and webhooks when an iCloud
|
|
63
|
+
session expires or a pass fails.
|
|
64
|
+
|
|
65
|
+
## Quick start
|
|
66
|
+
|
|
67
|
+
Run it with Docker, `ghcr.io/defts/immich-icloud-sync` for amd64 and arm64, and
|
|
68
|
+
[examples/compose.yaml](examples/compose.yaml) ([running it with Docker](docs/running.md#docker));
|
|
69
|
+
or install it with Python 3.12 or later: `uv tool install immich-icloud-sync` (or `pipx install`).
|
|
70
|
+
|
|
71
|
+
1. In Immich, create an API key for each person, with the permissions listed in
|
|
72
|
+
[the configuration](docs/configuration.md#account-one-per-apple-account).
|
|
73
|
+
2. Write a configuration: [examples/config.toml](examples/config.toml) shows every setting.
|
|
74
|
+
3. Sign each Apple account in, once. `auth` asks for the password and a two-factor code, and keeps
|
|
75
|
+
the session, never the password.
|
|
76
|
+
4. Check, look at what a pass would do, then run it.
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
immich-icloud-sync check --config config.toml
|
|
80
|
+
immich-icloud-sync auth alice --config config.toml
|
|
81
|
+
immich-icloud-sync run --dry-run --config config.toml
|
|
82
|
+
immich-icloud-sync daemon --config config.toml
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Commands
|
|
86
|
+
|
|
87
|
+
| Command | Does |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `check` | Shows the configuration, checks the server, each API key and the destination. |
|
|
90
|
+
| `auth <account>` | Signs an account in to iCloud and keeps the session. |
|
|
91
|
+
| `run [--dry-run] [--full]` | One pass, for cron or a systemd timer. `--full` reads every photo again. |
|
|
92
|
+
| `daemon` | Passes on schedule, with the HTTP API. |
|
|
93
|
+
| `status` | The last passes and the state of each account. |
|
|
94
|
+
| `trigger [--full]` | Asks the running daemon for a pass now. |
|
|
95
|
+
| `accept-deletions` | Lets the deletions the brake holds go at the next pass. |
|
|
96
|
+
|
|
97
|
+
Every command takes `--config`, or reads `$IMMICH_ICLOUD_SYNC_CONFIG`.
|
|
98
|
+
|
|
99
|
+
## Documentation
|
|
100
|
+
|
|
101
|
+
- [Configuration](docs/configuration.md): every setting.
|
|
102
|
+
- [Running it](docs/running.md): Docker, systemd, the API, metrics, webhooks, expired sessions.
|
|
103
|
+
- [Design](docs/design.md): how it works and why, findings about iCloud, safety invariants.
|
|
104
|
+
|
|
105
|
+
## Safety
|
|
106
|
+
|
|
107
|
+
- Nothing is ever written to iCloud: the iCloud side has no write method, and every request is
|
|
108
|
+
checked to be a read.
|
|
109
|
+
- Nothing is ever deleted for good from Immich: deletions, off by default, go to the trash, and
|
|
110
|
+
never follow from a read that missed a photo, nor touch a library that could not be read.
|
|
111
|
+
- A hidden photo is never visible, at any point of its import.
|
|
112
|
+
- Secrets come from files or environment variables, and never reach logs, the API or webhooks.
|
|
113
|
+
|
|
114
|
+
## Limits
|
|
115
|
+
|
|
116
|
+
- Accounts with Advanced Data Protection cannot be read: Apple keeps their photos out of reach of
|
|
117
|
+
the web.
|
|
118
|
+
- Apple asks for a new sign-in every few weeks; the daemon warns once a day until it is done.
|
|
119
|
+
- Spaces need Noodle Gallery; on Immich, shared photos go to an album.
|
|
120
|
+
- Photos already in Immich, imported by another tool, are not recognised: a file with the same
|
|
121
|
+
bytes is not stored twice, but one converted or recompressed is.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
Needs [uv](https://docs.astral.sh/uv/) and GNU Make; the integration tests need Docker.
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
make # lint, type check, unit tests with coverage
|
|
129
|
+
make integration # contract tests against a throwaway Immich server
|
|
130
|
+
make integration SERVER=noodle # the same against Noodle Gallery
|
|
131
|
+
make server-down SERVER=immich # remove a throwaway server
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The integration tests create users with a fixed password on the server they are given: never point
|
|
135
|
+
them at a server that matters. No test needs an Apple account.
|
|
136
|
+
|
|
137
|
+
This project is independent and not affiliated with Immich, FUTO, Noodle Gallery or Apple.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# immich-icloud-sync
|
|
2
|
+
|
|
3
|
+
One-way sync from iCloud Photos to [Immich](https://immich.app) and
|
|
4
|
+
[Noodle Gallery](https://github.com/open-noodle/gallery), built around the iCloud Shared Photo
|
|
5
|
+
Library: every photo lands in the account of the person who took it, and shared photos are also
|
|
6
|
+
published to a shared space or album.
|
|
7
|
+
|
|
8
|
+
```mermaid
|
|
9
|
+
flowchart LR
|
|
10
|
+
A[Alice's library] --> T[immich-icloud-sync]
|
|
11
|
+
B[Bob's library] --> T
|
|
12
|
+
S[Shared Library] --> T
|
|
13
|
+
T --> UA[Alice in Immich]
|
|
14
|
+
T --> UB[Bob in Immich]
|
|
15
|
+
T --> D[Family space<br>or shared album]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It runs on your server, reads iCloud through the same web service as icloud.com, and never writes
|
|
19
|
+
to iCloud.
|
|
20
|
+
|
|
21
|
+
**Status:** pre-release. Personal libraries and the Shared Library are imported and published;
|
|
22
|
+
edits, favourites, hiding and, if you turn them on, deletions follow Photos. See
|
|
23
|
+
[what is planned](docs/design.md#13-milestones).
|
|
24
|
+
|
|
25
|
+
## What it does
|
|
26
|
+
|
|
27
|
+
- **Each photo to its owner.** A personal library goes to its account; a Shared Library photo goes
|
|
28
|
+
to whoever put it there, or to the owner of the camera that took it.
|
|
29
|
+
- **Shared photos, shared.** Shared Library photos are also added to a Noodle Gallery space or an
|
|
30
|
+
Immich album, once: one removed from there stays removed.
|
|
31
|
+
- **As Photos shows them.** Originals, the edited version stacked on top (a newer edit goes on
|
|
32
|
+
top, an edit undone puts the original back there, old edits stay below), Live Photo videos; the
|
|
33
|
+
date and time, the place and the caption as Photos has them, corrections included. Hidden photos
|
|
34
|
+
go to the owner's locked folder.
|
|
35
|
+
- **Favourites follow Photos.** A favourite set or removed in Photos is applied in Immich; one set
|
|
36
|
+
in Immich stays. A photo hidden later goes to the locked folder.
|
|
37
|
+
- **Deletions, if you want them.** Off by default. Turned on, a photo deleted in Photos goes to
|
|
38
|
+
the Immich trash, and comes back if it is taken out of Recently Deleted, under guards: a window,
|
|
39
|
+
a daily brake, a delay for personal libraries.
|
|
40
|
+
- **Incremental.** A pass reads what changed since the previous one; a weekly pass reads everything
|
|
41
|
+
again. A pass stopped anywhere is finished by the next, without duplicates.
|
|
42
|
+
- **Unattended.** A daemon with an HTTP API, Prometheus metrics, and webhooks when an iCloud
|
|
43
|
+
session expires or a pass fails.
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
Run it with Docker, `ghcr.io/defts/immich-icloud-sync` for amd64 and arm64, and
|
|
48
|
+
[examples/compose.yaml](examples/compose.yaml) ([running it with Docker](docs/running.md#docker));
|
|
49
|
+
or install it with Python 3.12 or later: `uv tool install immich-icloud-sync` (or `pipx install`).
|
|
50
|
+
|
|
51
|
+
1. In Immich, create an API key for each person, with the permissions listed in
|
|
52
|
+
[the configuration](docs/configuration.md#account-one-per-apple-account).
|
|
53
|
+
2. Write a configuration: [examples/config.toml](examples/config.toml) shows every setting.
|
|
54
|
+
3. Sign each Apple account in, once. `auth` asks for the password and a two-factor code, and keeps
|
|
55
|
+
the session, never the password.
|
|
56
|
+
4. Check, look at what a pass would do, then run it.
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
immich-icloud-sync check --config config.toml
|
|
60
|
+
immich-icloud-sync auth alice --config config.toml
|
|
61
|
+
immich-icloud-sync run --dry-run --config config.toml
|
|
62
|
+
immich-icloud-sync daemon --config config.toml
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Commands
|
|
66
|
+
|
|
67
|
+
| Command | Does |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `check` | Shows the configuration, checks the server, each API key and the destination. |
|
|
70
|
+
| `auth <account>` | Signs an account in to iCloud and keeps the session. |
|
|
71
|
+
| `run [--dry-run] [--full]` | One pass, for cron or a systemd timer. `--full` reads every photo again. |
|
|
72
|
+
| `daemon` | Passes on schedule, with the HTTP API. |
|
|
73
|
+
| `status` | The last passes and the state of each account. |
|
|
74
|
+
| `trigger [--full]` | Asks the running daemon for a pass now. |
|
|
75
|
+
| `accept-deletions` | Lets the deletions the brake holds go at the next pass. |
|
|
76
|
+
|
|
77
|
+
Every command takes `--config`, or reads `$IMMICH_ICLOUD_SYNC_CONFIG`.
|
|
78
|
+
|
|
79
|
+
## Documentation
|
|
80
|
+
|
|
81
|
+
- [Configuration](docs/configuration.md): every setting.
|
|
82
|
+
- [Running it](docs/running.md): Docker, systemd, the API, metrics, webhooks, expired sessions.
|
|
83
|
+
- [Design](docs/design.md): how it works and why, findings about iCloud, safety invariants.
|
|
84
|
+
|
|
85
|
+
## Safety
|
|
86
|
+
|
|
87
|
+
- Nothing is ever written to iCloud: the iCloud side has no write method, and every request is
|
|
88
|
+
checked to be a read.
|
|
89
|
+
- Nothing is ever deleted for good from Immich: deletions, off by default, go to the trash, and
|
|
90
|
+
never follow from a read that missed a photo, nor touch a library that could not be read.
|
|
91
|
+
- A hidden photo is never visible, at any point of its import.
|
|
92
|
+
- Secrets come from files or environment variables, and never reach logs, the API or webhooks.
|
|
93
|
+
|
|
94
|
+
## Limits
|
|
95
|
+
|
|
96
|
+
- Accounts with Advanced Data Protection cannot be read: Apple keeps their photos out of reach of
|
|
97
|
+
the web.
|
|
98
|
+
- Apple asks for a new sign-in every few weeks; the daemon warns once a day until it is done.
|
|
99
|
+
- Spaces need Noodle Gallery; on Immich, shared photos go to an album.
|
|
100
|
+
- Photos already in Immich, imported by another tool, are not recognised: a file with the same
|
|
101
|
+
bytes is not stored twice, but one converted or recompressed is.
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
Needs [uv](https://docs.astral.sh/uv/) and GNU Make; the integration tests need Docker.
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
make # lint, type check, unit tests with coverage
|
|
109
|
+
make integration # contract tests against a throwaway Immich server
|
|
110
|
+
make integration SERVER=noodle # the same against Noodle Gallery
|
|
111
|
+
make server-down SERVER=immich # remove a throwaway server
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The integration tests create users with a fixed password on the server they are given: never point
|
|
115
|
+
them at a server that matters. No test needs an Apple account.
|
|
116
|
+
|
|
117
|
+
This project is independent and not affiliated with Immich, FUTO, Noodle Gallery or Apple.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "immich-icloud-sync"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "One-way sync from iCloud Photos to Immich and Noodle Gallery, built around the iCloud Shared Photo Library."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Environment :: Console",
|
|
12
|
+
"Operating System :: POSIX :: Linux",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Topic :: Multimedia :: Graphics",
|
|
15
|
+
]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"httpx>=0.28",
|
|
18
|
+
"pydantic>=2.11",
|
|
19
|
+
"pyicloud>=2026.11.2,<2027",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Source = "https://github.com/defts/immich-icloud-sync"
|
|
24
|
+
Documentation = "https://github.com/defts/immich-icloud-sync/tree/main/docs"
|
|
25
|
+
Issues = "https://github.com/defts/immich-icloud-sync/issues"
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
immich-icloud-sync = "immich_icloud_sync.cli:main"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.13.9,<0.14"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"coverage>=7.10",
|
|
37
|
+
"mypy>=2.4",
|
|
38
|
+
"pytest>=9",
|
|
39
|
+
"ruff>=0.17",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 100
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = [
|
|
47
|
+
"A",
|
|
48
|
+
"ARG",
|
|
49
|
+
"B",
|
|
50
|
+
"C4",
|
|
51
|
+
"DTZ",
|
|
52
|
+
"E",
|
|
53
|
+
"ERA",
|
|
54
|
+
"F",
|
|
55
|
+
"FBT",
|
|
56
|
+
"I",
|
|
57
|
+
"N",
|
|
58
|
+
"PL",
|
|
59
|
+
"PLR0917",
|
|
60
|
+
"PT",
|
|
61
|
+
"PTH",
|
|
62
|
+
"RET",
|
|
63
|
+
"RUF",
|
|
64
|
+
"S",
|
|
65
|
+
"SIM",
|
|
66
|
+
"T20",
|
|
67
|
+
"TRY",
|
|
68
|
+
"UP",
|
|
69
|
+
"W",
|
|
70
|
+
]
|
|
71
|
+
ignore = [
|
|
72
|
+
"N818",
|
|
73
|
+
"PLR0913",
|
|
74
|
+
"TRY003",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint.per-file-ignores]
|
|
78
|
+
"tests/**" = [
|
|
79
|
+
"PLR2004",
|
|
80
|
+
"S101",
|
|
81
|
+
"S105",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[tool.mypy]
|
|
85
|
+
strict = true
|
|
86
|
+
files = [
|
|
87
|
+
"src",
|
|
88
|
+
"tests",
|
|
89
|
+
]
|
|
90
|
+
plugins = ["pydantic.mypy"]
|
|
91
|
+
|
|
92
|
+
[[tool.mypy.overrides]]
|
|
93
|
+
module = [
|
|
94
|
+
"pyicloud",
|
|
95
|
+
"pyicloud.*",
|
|
96
|
+
]
|
|
97
|
+
follow_untyped_imports = true
|
|
98
|
+
|
|
99
|
+
[tool.pydantic-mypy]
|
|
100
|
+
init_forbid_extra = true
|
|
101
|
+
init_typed = true
|
|
102
|
+
warn_required_dynamic_aliases = true
|
|
103
|
+
|
|
104
|
+
[tool.pytest.ini_options]
|
|
105
|
+
addopts = [
|
|
106
|
+
"--strict-markers",
|
|
107
|
+
"--strict-config",
|
|
108
|
+
"-ra",
|
|
109
|
+
"-m",
|
|
110
|
+
"not integration",
|
|
111
|
+
]
|
|
112
|
+
testpaths = ["tests"]
|
|
113
|
+
markers = ["integration: needs a real Immich or Noodle Gallery server (make integration)"]
|
|
114
|
+
filterwarnings = ["error"]
|
|
115
|
+
xfail_strict = true
|
|
116
|
+
|
|
117
|
+
[tool.coverage.run]
|
|
118
|
+
branch = true
|
|
119
|
+
source = ["immich_icloud_sync"]
|
|
120
|
+
omit = ["*/__main__.py"]
|
|
121
|
+
|
|
122
|
+
[tool.coverage.report]
|
|
123
|
+
fail_under = 90
|
|
124
|
+
show_missing = true
|
|
125
|
+
skip_covered = true
|
|
126
|
+
exclude_also = [
|
|
127
|
+
"if TYPE_CHECKING:",
|
|
128
|
+
'^\s*\.\.\.$',
|
|
129
|
+
]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "immich-icloud-sync"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "One-way sync from iCloud Photos to Immich and Noodle Gallery, built around the iCloud Shared Photo Library."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Environment :: Console",
|
|
12
|
+
"Operating System :: POSIX :: Linux",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Topic :: Multimedia :: Graphics",
|
|
15
|
+
]
|
|
16
|
+
urls = { Source = "https://github.com/defts/immich-icloud-sync", Documentation = "https://github.com/defts/immich-icloud-sync/tree/main/docs", Issues = "https://github.com/defts/immich-icloud-sync/issues" }
|
|
17
|
+
dependencies = [
|
|
18
|
+
"httpx>=0.28",
|
|
19
|
+
"pydantic>=2.11",
|
|
20
|
+
"pyicloud>=2026.11.2,<2027",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
immich-icloud-sync = "immich_icloud_sync.cli:main"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["uv_build>=0.13.9,<0.14"]
|
|
28
|
+
build-backend = "uv_build"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"coverage>=7.10",
|
|
33
|
+
"mypy>=2.4",
|
|
34
|
+
"pytest>=9",
|
|
35
|
+
"ruff>=0.17",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 100
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
select = [
|
|
43
|
+
"A", # builtins shadowing
|
|
44
|
+
"ARG", # unused arguments
|
|
45
|
+
"B", # bugbear
|
|
46
|
+
"C4", # comprehensions
|
|
47
|
+
"DTZ", # naive datetimes
|
|
48
|
+
"E", # pycodestyle errors
|
|
49
|
+
"ERA", # commented-out code
|
|
50
|
+
"F", # pyflakes
|
|
51
|
+
"FBT", # boolean positional arguments
|
|
52
|
+
"I", # import order
|
|
53
|
+
"N", # naming
|
|
54
|
+
"PL", # pylint
|
|
55
|
+
"PLR0917", # positional arguments
|
|
56
|
+
"PT", # pytest style
|
|
57
|
+
"PTH", # pathlib
|
|
58
|
+
"RET", # returns
|
|
59
|
+
"RUF", # ruff
|
|
60
|
+
"S", # bandit
|
|
61
|
+
"SIM", # simplifications
|
|
62
|
+
"T20", # print
|
|
63
|
+
"TRY", # exceptions
|
|
64
|
+
"UP", # pyupgrade
|
|
65
|
+
"W", # pycodestyle warnings
|
|
66
|
+
]
|
|
67
|
+
ignore = [
|
|
68
|
+
"N818", # a subclass of a ...Error names the situation: ImmichRefused, ImmichUnreachable
|
|
69
|
+
"PLR0913", # long signatures are keyword-only: PLR0917 limits the positional arguments
|
|
70
|
+
"TRY003", # messages are written where the error is raised, on purpose
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint.per-file-ignores]
|
|
74
|
+
"tests/**" = [
|
|
75
|
+
"PLR2004", # literal values are the point of a test
|
|
76
|
+
"S101", # assert
|
|
77
|
+
"S105", # sync tokens and test keys are not passwords
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
[tool.mypy]
|
|
81
|
+
strict = true
|
|
82
|
+
files = ["src", "tests"]
|
|
83
|
+
plugins = ["pydantic.mypy"]
|
|
84
|
+
|
|
85
|
+
[[tool.mypy.overrides]]
|
|
86
|
+
module = ["pyicloud", "pyicloud.*"]
|
|
87
|
+
follow_untyped_imports = true # annotated, but ships no py.typed marker
|
|
88
|
+
|
|
89
|
+
[tool.pydantic-mypy]
|
|
90
|
+
init_forbid_extra = true
|
|
91
|
+
init_typed = true
|
|
92
|
+
warn_required_dynamic_aliases = true
|
|
93
|
+
|
|
94
|
+
[tool.pytest.ini_options]
|
|
95
|
+
addopts = ["--strict-markers", "--strict-config", "-ra", "-m", "not integration"]
|
|
96
|
+
testpaths = ["tests"]
|
|
97
|
+
markers = ["integration: needs a real Immich or Noodle Gallery server (make integration)"]
|
|
98
|
+
filterwarnings = ["error"]
|
|
99
|
+
xfail_strict = true
|
|
100
|
+
|
|
101
|
+
[tool.coverage.run]
|
|
102
|
+
branch = true
|
|
103
|
+
source = ["immich_icloud_sync"]
|
|
104
|
+
omit = ["*/__main__.py"] # run by a subprocess in tests/test_cli.py
|
|
105
|
+
|
|
106
|
+
[tool.coverage.report]
|
|
107
|
+
fail_under = 90
|
|
108
|
+
show_missing = true
|
|
109
|
+
skip_covered = true
|
|
110
|
+
exclude_also = [
|
|
111
|
+
"if TYPE_CHECKING:",
|
|
112
|
+
"^\\s*\\.\\.\\.$",
|
|
113
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""The daemon's HTTP API: health, status, the passes of late, metrics, and asking for a pass (§9).
|
|
2
|
+
|
|
3
|
+
It answers on its own thread. Every endpoint but `/healthz` needs the bearer token when one is
|
|
4
|
+
set; one is required as soon as the API listens beyond this machine (D14).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import hmac
|
|
8
|
+
import json
|
|
9
|
+
import socket
|
|
10
|
+
import threading
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from http import HTTPStatus
|
|
14
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
15
|
+
from typing import Any
|
|
16
|
+
from urllib.parse import parse_qs, urlsplit
|
|
17
|
+
|
|
18
|
+
from immich_icloud_sync.daemon.runner import Trigger
|
|
19
|
+
|
|
20
|
+
MAX_RUNS = 100
|
|
21
|
+
MAX_BODY = 1024
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class Views:
|
|
26
|
+
"""What the API shows, each read when asked."""
|
|
27
|
+
|
|
28
|
+
status: Callable[[], dict[str, Any]]
|
|
29
|
+
runs: Callable[[int], list[dict[str, Any]]]
|
|
30
|
+
metrics: Callable[[], str]
|
|
31
|
+
accept: Callable[[], int] # accepts the deletions the brake holds; how many
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ListenFailed(Exception):
|
|
35
|
+
"""The API cannot listen where the configuration says."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Api:
|
|
39
|
+
def __init__(
|
|
40
|
+
self, *, listen: tuple[str, int], token: str | None, views: Views, trigger: Trigger
|
|
41
|
+
) -> None:
|
|
42
|
+
handler = _handler(token, views, trigger)
|
|
43
|
+
host, port = listen
|
|
44
|
+
server = ThreadingHTTPServer
|
|
45
|
+
if ":" in host:
|
|
46
|
+
server = _IPv6Server
|
|
47
|
+
try:
|
|
48
|
+
self._server = server(listen, handler)
|
|
49
|
+
except OSError as error:
|
|
50
|
+
raise ListenFailed(
|
|
51
|
+
f"the API cannot listen on {host}:{port}: {error.strerror}"
|
|
52
|
+
) from None
|
|
53
|
+
self._thread = threading.Thread(target=self._server.serve_forever, daemon=True)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def address(self) -> tuple[str, int]:
|
|
57
|
+
host, port = self._server.server_address[:2]
|
|
58
|
+
return str(host), int(port)
|
|
59
|
+
|
|
60
|
+
def start(self) -> None:
|
|
61
|
+
self._thread.start()
|
|
62
|
+
|
|
63
|
+
def stop(self) -> None:
|
|
64
|
+
self._server.shutdown()
|
|
65
|
+
self._server.server_close()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class _IPv6Server(ThreadingHTTPServer):
|
|
69
|
+
address_family = socket.AF_INET6
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _handler(token: str | None, views: Views, trigger: Trigger) -> type[BaseHTTPRequestHandler]:
|
|
73
|
+
class Handler(BaseHTTPRequestHandler):
|
|
74
|
+
server_version = "immich-icloud-sync"
|
|
75
|
+
|
|
76
|
+
def do_GET(self) -> None:
|
|
77
|
+
path, query = self._target()
|
|
78
|
+
if path == "/healthz":
|
|
79
|
+
self._send(HTTPStatus.OK, "text/plain", b"ok\n")
|
|
80
|
+
elif not self._allowed():
|
|
81
|
+
return
|
|
82
|
+
elif path == "/api/v1/status":
|
|
83
|
+
self._json(HTTPStatus.OK, views.status())
|
|
84
|
+
elif path == "/api/v1/runs":
|
|
85
|
+
limit = query.get("limit", ["20"])[0]
|
|
86
|
+
count = min(int(limit), MAX_RUNS) if limit.isdigit() else 20
|
|
87
|
+
self._json(HTTPStatus.OK, views.runs(count))
|
|
88
|
+
elif path == "/metrics":
|
|
89
|
+
text = views.metrics().encode()
|
|
90
|
+
self._send(HTTPStatus.OK, "text/plain; version=0.0.4", text)
|
|
91
|
+
else:
|
|
92
|
+
self._json(HTTPStatus.NOT_FOUND, {"error": "no such endpoint"})
|
|
93
|
+
|
|
94
|
+
def do_POST(self) -> None:
|
|
95
|
+
path, _ = self._target()
|
|
96
|
+
if not self._allowed():
|
|
97
|
+
return
|
|
98
|
+
if path == "/api/v1/deletions/accept":
|
|
99
|
+
self._json(HTTPStatus.OK, {"accepted": views.accept()})
|
|
100
|
+
return
|
|
101
|
+
if path != "/api/v1/sync":
|
|
102
|
+
self._json(HTTPStatus.NOT_FOUND, {"error": "no such endpoint"})
|
|
103
|
+
return
|
|
104
|
+
given = self.headers.get("Content-Length", "0")
|
|
105
|
+
length = int(given) if given.isdigit() else 0
|
|
106
|
+
try:
|
|
107
|
+
asked = json.loads(self.rfile.read(min(length, MAX_BODY)) or b"{}")
|
|
108
|
+
full = asked.get("full", False) is True if isinstance(asked, dict) else False
|
|
109
|
+
except ValueError:
|
|
110
|
+
self._json(HTTPStatus.BAD_REQUEST, {"error": "the body is not JSON"})
|
|
111
|
+
return
|
|
112
|
+
trigger.ask(full=full)
|
|
113
|
+
self._json(HTTPStatus.ACCEPTED, {"queued": True, "full": full})
|
|
114
|
+
|
|
115
|
+
def log_message(self, format: str, *args: Any) -> None: # noqa: A002 — the base's name
|
|
116
|
+
"""Requests are not logged: a token could show up in a misused URL."""
|
|
117
|
+
|
|
118
|
+
def _target(self) -> tuple[str, dict[str, list[str]]]:
|
|
119
|
+
parts = urlsplit(self.path)
|
|
120
|
+
return parts.path, parse_qs(parts.query)
|
|
121
|
+
|
|
122
|
+
def _allowed(self) -> bool:
|
|
123
|
+
if token is None:
|
|
124
|
+
return True
|
|
125
|
+
given = self.headers.get("Authorization", "")
|
|
126
|
+
if hmac.compare_digest(given.encode(), f"Bearer {token}".encode()):
|
|
127
|
+
return True
|
|
128
|
+
self._json(HTTPStatus.UNAUTHORIZED, {"error": "a bearer token is needed"})
|
|
129
|
+
return False
|
|
130
|
+
|
|
131
|
+
def _json(self, status: HTTPStatus, body: Any) -> None:
|
|
132
|
+
self._send(status, "application/json", json.dumps(body, default=str).encode())
|
|
133
|
+
|
|
134
|
+
def _send(self, status: HTTPStatus, kind: str, body: bytes) -> None:
|
|
135
|
+
self.send_response(status)
|
|
136
|
+
self.send_header("Content-Type", kind)
|
|
137
|
+
self.send_header("Content-Length", str(len(body)))
|
|
138
|
+
self.end_headers()
|
|
139
|
+
self.wfile.write(body)
|
|
140
|
+
|
|
141
|
+
return Handler
|