The fastest way to edit photos is with a single function call:
import asyncioimport osfrom pathlib import Pathfrom imagen_sdk import quick_editasync def main(): # Get API key from environment api_key = os.getenv("IMAGEN_API_KEY", "your_api_key_here") # Find photos to edit photos = [f for f in Path(".").glob("./sample_photos/*.dng") if f.is_file()] if not photos: print("No .dng files found. Add some photos to this directory.") return print(f"Editing {len(photos)} photos...") try: # Edit photos with AI result = await quick_edit( api_key=api_key, profile_key=5700, image_paths=[str(p) for p in photos], download=True, download_dir="edited", export=True, ) print(f"✅ Done! {len(result.downloaded_files)} edited photos saved to ./edited/") except Exception as e: print(f"❌ Error: {e}") print("💡 Make sure your API key is set: export IMAGEN_API_KEY='your_key'")if __name__ == "__main__": asyncio.run(main())
Use the SDK’s file format constants to discover photos:
from pathlib import Pathfrom imagen_sdk import RAW_EXTENSIONS, JPG_EXTENSIONS# Find RAW filesraw_photos = []for ext in RAW_EXTENSIONS: raw_photos.extend([str(p) for p in Path('.').glob(f'*{ext}')])# Find JPEG files (separate project needed)jpeg_photos = []for ext in JPG_EXTENSIONS: jpeg_photos.extend([str(p) for p in Path('.').glob(f'*{ext}')])# Process RAW files first (if any)if raw_photos: print(f"Processing {len(raw_photos)} RAW files...") result = await quick_edit( api_key="your_api_key", profile_key=5700, image_paths=raw_photos, edit_options=EditOptions(crop=True, straighten=True), download=True )elif jpeg_photos: print(f"Processing {len(jpeg_photos)} JPEG files...") result = await quick_edit( api_key="your_api_key", profile_key=5700, image_paths=jpeg_photos, edit_options=EditOptions(crop=True, straighten=True), download=True )
A single project can contain either RAW files or JPEG files, but not both. Each file type must be in a separate project.
import loggingfrom imagen_sdk import quick_edit# Set up a custom loggerlogger = logging.getLogger("imagen_sdk.examples")handler = logging.StreamHandler()formatter = logging.Formatter("[%(levelname)s] %(name)s: %(message)s")handler.setFormatter(formatter)logger.addHandler(handler)logger.setLevel(logging.INFO)# Use logger with quick_editresult = await quick_edit( api_key=api_key, profile_key=5700, image_paths=[str(p) for p in photos], download=True, download_dir="edited", logger=logger, logger_level=logging.INFO,)
The SDK supports a wide range of camera RAW formats and JPEG files:RAW formats: .dng, .nef, .cr2, .cr3, .arw, .nrw, .crw, .srf, .sr2, .orf, .raw, .rw2, .raf, .ptx, .pef, .rwl, .srw, .3fr, .fffJPEG formats: .jpg, .jpeg
from imagen_sdk import SUPPORTED_FILE_FORMATS, RAW_EXTENSIONS, JPG_EXTENSIONS# Check if file is supportedfile_ext = Path("photo.cr2").suffix.lower()is_supported = file_ext in SUPPORTED_FILE_FORMATSis_raw = file_ext in RAW_EXTENSIONSis_jpeg = file_ext in JPG_EXTENSIONS