{"library":"pyobjc-framework-coreml","title":"PyObjC CoreML Framework","description":"PyObjC-framework-CoreML provides Python wrappers for Apple's CoreML framework on macOS, enabling Python applications to interact with Core ML models. It is part of the larger PyObjC project, which creates a bridge between Python and Objective-C, and is actively maintained with releases often aligned with macOS updates. The current version is 12.1.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pyobjc-framework-coreml"],"cli":null},"imports":["import CoreML","from CoreML import MLModel"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import CoreML\nimport Foundation # Often needed for NSURL, NSBundle etc.\nimport os\n\n# --- This example demonstrates attempting to load a CoreML model ---\n# In a real scenario, 'your_model.mlmodel' would be a path to an actual Core ML model file.\n# For demonstration, we'll try a dummy path or look for a model in the app bundle.\n# Replace with the actual path to your .mlmodel file or ensure it's in your app bundle.\n\n# Option 1: Direct path (replace with actual path)\nmodel_path = os.environ.get('COREML_MODEL_PATH', '/tmp/your_model.mlmodel')\n\n# Option 2: Attempt to find in the main bundle (common for macOS apps)\n# mainBundle = Foundation.NSBundle.mainBundle()\n# model_path_from_bundle = mainBundle.pathForResource_ofType_(\"YourModelName\", \"mlmodel\")\n# if model_path_from_bundle:\n#     model_path = model_path_from_bundle\n\nprint(f\"Attempting to load CoreML model from: {model_path}\")\n\ntry:\n    # CoreML methods often follow Objective-C conventions, e.g., 'methodName_error_'\n    # for methods that take an NSError** parameter in Objective-C.\n    # The PyObjC bridge translates this into a tuple (result, error_object).\n    model, error = CoreML.MLModel.modelWithContentsOfURL_error_( \n        Foundation.NSURL.fileURLWithPath_(model_path), None\n    )\n    \n    if error:\n        print(f\"Error loading model: {error.localizedDescription()}\")\n    elif model:\n        print(f\"Successfully loaded CoreML model: {model}\")\n        print(f\"Model description: {model.modelDescription()}\")\n        # You can now interact with the model, e.g., for predictions:\n        # input_features = CoreML.MLFeatureProvider.alloc().init()\n        # prediction, pred_error = model.predictionFromFeatures_error_(input_features, None)\n        # if not pred_error: print(f\"Prediction: {prediction}\")\n    else:\n        print(\"Failed to load model without explicit error or model object.\")\n\nexcept Exception as e:\n    print(f\"An unexpected Python exception occurred: {e}\")\n\nprint(f\"\\nAccessing MLModel class directly: {CoreML.MLModel}\")","lang":"python","description":"This quickstart demonstrates how to import the `CoreML` framework and attempt to load an `MLModel` using PyObjC. It highlights the typical PyObjC pattern for handling Objective-C methods that return errors by reference. A functional example would require an actual `.mlmodel` file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":null,"pypi_latest":"12.1","is_stale":null,"summary":{"python_range":"3.10–3.9","success_rate":0,"avg_install_s":null,"avg_import_s":null,"wheel_type":null},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.1,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.6,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyobjc-framework-coreml","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.6,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}