juno.photos¶
Pick photos from the user’s library and save images to the camera roll.
Two surfaces:
pick()opens iOS’s system photo picker (PHPickerViewController) and returns the user’s selection as a list ofPhotorecords. The picker runs out-of-process and does not require photo library authorization — the user’s selection is delivered to the app, not the library itself.save()writes encoded image bytes to the camera roll. Needs add-only photo library authorization (NSPhotoLibraryAddUsageDescription).
Authorization helpers report write (add-only) permission status —
pick() is unaffected by them. Authorization waits are polled
from Python so Juno’s Stop button can interrupt the prompt via
KeyboardInterrupt (same pattern as juno.location /
juno.contacts / juno.reminders).
Typical usage:
from juno import photos
# Picker — no permission required
selection = photos.pick(limit=3)
for photo in selection:
print(photo.filename, photo.mime_type, len(photo.data))
# Save — requires add-only authorization
if photos.request_authorization() == photos.AuthorizationStatus.AUTHORIZED:
with open("/path/to/sunset.jpg", "rb") as f:
photos.save(f.read(), format="jpeg")
Notes:
limitedauthorization (iOS 14+) reports viaauthorization_status()butis_authorized()returnsFalse— every save under limited access would re-prompt the user to pick which assets the app may see, which is not what most scripts expect.The picker runs as a separate process; large selections may take several seconds to deliver bytes back. Stop interrupts the wait cleanly.
- class juno.photos.AuthorizationStatus¶
Bases:
objectString constants returned by
authorization_status().
- class juno.photos.Photo(data, mime_type='application/octet-stream', filename='', width=0, height=0)¶
Bases:
objectA single photo picked from the user’s library.
datais the raw encoded bytes — typically JPEG or HEIC, matching the on-disk asset.mime_typeis a best-effort string derived from the picker’s registered type identifiers ("image/jpeg","image/heic","image/png","application/octet-stream"if the type is unknown).filenameis the suggested name from the picker (often empty for assets without one).width/heightare pixel dimensions;0if decoding the data didn’t yield a valid image.
- juno.photos.authorization_status()¶
Return the current photo-library add-only authorization status.
- Returns:
One of the
AuthorizationStatusstring constants.- Return type:
Note
This reports write (add-only) permission.
pick()does not depend on it — the system picker runs out-of-process and delivers selected assets without any library authorization.
- juno.photos.is_authorized()¶
Return
Trueif the app has full add-only photo-library authorization.iOS 14
limitedaccess returnsFalse— under limited access every save re-prompts the user, which is not what scripts typically expect.- Return type:
- juno.photos.request_authorization()¶
Request photo-library add-only authorization.
Triggers the system permission prompt if status is
notDetermined; returns the existing status otherwise. Pollsauthorization_status()from Python so the Stop button can interrupt the wait viaKeyboardInterrupt.- Returns:
Resolved authorization status, one of the
AuthorizationStatusconstants.- Return type:
- juno.photos.pick(*, limit=1)¶
Open the system photo picker and return the selection.
- Parameters:
limit (int) – Maximum number of photos the user can pick.
0means no limit (the system caps the actual cap). Must be a non-negative integer.- Returns:
A list of
Photorecords, possibly empty (the user dismissed the picker without selecting anything).- Raises:
TypeError – If
limitis not an int.ValueError – If
limitis negative.RuntimeError – If the picker presentation failed (no top-level view controller, system error, etc.).
- Return type:
Note
pickdoes not require photo-library authorization — thePHPickerViewControllerruns out-of-process and the user’s selection is delivered to the app directly.Stopcleanly unwinds the wait while the picker is on screen.
- juno.photos.save(data, *, format='jpeg')¶
Save encoded image bytes to the camera roll.
- Parameters:
data (bytes | bytearray | memoryview) – Encoded image bytes (JPEG / PNG / HEIC). Empty buffers are rejected before reaching the system.
format (str) – Informational hint about the byte format. One of
"jpeg"/"png"/"heic".
- Returns:
Trueon success;Falseon save failure (system rejected the bytes, write was cancelled, etc.).- Raises:
TypeError – If
datais not a bytes-like object, orformatis not a string.ValueError – If
datais empty, orformatis not one of the accepted values.PermissionError – If add-only photo authorization is denied, restricted, or limited.
- Return type: