PyIMG4

0.8.8 · active · verified Thu Apr 16

PyIMG4 is a Python library and CLI tool designed for parsing, manipulating, and creating Apple's proprietary Image4 format, including IMG4, IM4M (manifest), and IM4P (payload) files. It is currently at version 0.8.8 and maintains a relatively active release cadence, with updates addressing bugs, adding features, and refining internal logic.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse an Image4 file, display its contents, and extract the IM4P payload data using PyIMG4. It simulates reading a dummy Image4 file for immediate execution.

from pyimg4 import IMG4

# Example: Extracting IM4P payload from an IMG4 file
try:
    # Simulate reading an IMG4 file (replace 'path/to/myfile.img4' with actual path)
    # For demonstration, we create a dummy file. In a real scenario, this would be `open('myfile.img4', 'rb')`
    dummy_img4_data = b'IMG4\x00\x00\x00\x01\x00\x00\x00\x00IM4P\x00\x00\x00\x01\x00\x00\x00\x00ABCD\x00\x00\x00\x08\x00\x00\x00\x00IM4M\x00\x00\x00\x01\x00\x00\x00\x00MNFT\x00\x00\x00\x04DATA'
    
    # Open the IMG4 file (or use dummy data as shown)
    i = IMG4(dummy_img4_data)

    print("IMG4 file content:")
    i.show() # Display the structure of the IMG4 object

    # Extract and print the IM4P payload data
    if i.IM4P and i.IM4P.DATA:
        print("\nExtracted IM4P Payload Data (first 100 bytes):")
        print(i.IM4P.DATA[:100])
    else:
        print("No IM4P payload data found.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →