Registry / ai-ml / pyobjc-framework-coreml

pyobjc-framework-coreml

JSON →
library12.2.2pypypiunverified

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.

pip install pyobjc-framework-coreml
INSTALL
IMPORT
SIG · PYOBJC-FRAMEWORK-C
P
pyobjc-framework-coreml
ai-mlpythonv12.2.2
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CoreML
import CoreML
All CoreML classes and functions are typically exposed under the `CoreML` top-level module.
MLModel
from CoreML import MLModel
Specific CoreML classes can be imported directly for brevity.

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.

import CoreML import Foundation # Often needed for NSURL, NSBundle etc. import os # --- This example demonstrates attempting to load a CoreML model --- # In a real scenario, 'your_model.mlmodel' would be a path to an actual Core ML model file. # For demonstration, we'll try a dummy path or look for a model in the app bundle. # Replace with the actual path to your .mlmodel file or ensure it's in your app bundle. # Option 1: Direct path (replace with actual path) model_path = os.environ.get('COREML_MODEL_PATH', '/tmp/your_model.mlmodel') # Option 2: Attempt to find in the main bundle (common for macOS apps) # mainBundle = Foundation.NSBundle.mainBundle() # model_path_from_bundle = mainBundle.pathForResource_ofType_("YourModelName", "mlmodel") # if model_path_from_bundle: # model_path = model_path_from_bundle print(f"Attempting to load CoreML model from: {model_path}") try: # CoreML methods often follow Objective-C conventions, e.g., 'methodName_error_' # for methods that take an NSError** parameter in Objective-C. # The PyObjC bridge translates this into a tuple (result, error_object). model, error = CoreML.MLModel.modelWithContentsOfURL_error_( Foundation.NSURL.fileURLWithPath_(model_path), None ) if error: print(f"Error loading model: {error.localizedDescription()}") elif model: print(f"Successfully loaded CoreML model: {model}") print(f"Model description: {model.modelDescription()}") # You can now interact with the model, e.g., for predictions: # input_features = CoreML.MLFeatureProvider.alloc().init() # prediction, pred_error = model.predictionFromFeatures_error_(input_features, None) # if not pred_error: print(f"Prediction: {prediction}") else: print("Failed to load model without explicit error or model object.") except Exception as e: print(f"An unexpected Python exception occurred: {e}") print(f"\nAccessing MLModel class directly: {CoreML.MLModel}")
Debug
Known issues
breakingPyObjC 12.0 dropped support for Python 3.9. Users must ensure their environment uses Python 3.10 or later. PyObjC 11.0 also dropped support for Python 3.8.
fix
Upgrade Python to version 3.10 or higher.
affects: >=12.0
breakingPyObjC 11.1 aligned its memory management behavior for `init` methods with `clang`'s Automatic Reference Counting (ARC). Methods in the `init` family now correctly steal a reference to `self` and return a new one. This change might affect code relying on previous PyObjC reference counting behavior for initializers.
fix
Review and update code interacting with Objective-C `init` methods to ensure correct reference handling, especially for complex object graphs or custom subclasses.
affects: >=11.1
gotchaIn PyObjC 10.3, a change broke the ability to use Python's `__init__` when a user also implements `__new__` for an Objective-C subclass. While 10.3.1 partially re-introduced this, classes relying on `__new__` provided by PyObjC still cannot use `__init__`.
fix
If subclassing Objective-C classes, avoid implementing both `__new__` and `__init__` in Python for versions 10.3 and later, or carefully test behavior when a user-defined `__new__` is present.
affects: 10.3 - 10.3.x
breakingThe `IMServicePlugIn` bindings were completely removed in PyObjC 10.0. This framework was deprecated by Apple in macOS 10.13 and removed in macOS 14.
fix
Migrate away from the `IMServicePlugIn` framework. There is no direct replacement in newer macOS versions via PyObjC.
affects: >=10.0
gotchaWhile PyObjC 11.0 introduced *experimental* support for free-threading (`PEP 703`) with Python 3.13, PyObjC 10.3 explicitly stated it does *not* support experimental free-threading in Python 3.13. Users should exercise caution and thoroughly test when using free-threading with PyObjC, especially with specific framework bindings.
fix
Avoid relying on Python 3.13's experimental free-threading features with PyObjC unless explicitly confirmed as stable and supported for your specific PyObjC version and frameworks.
affects: 10.3 - 11.x
Upgrade
Version history
12.2.2latest on PyPI · released Aug 11, 2026
Audit
Dependencies
pyobjc-corerequiredProvides the core Python to Objective-C bridge functionalities.
pyobjc-framework-cocoarequiredProvides common Cocoa (Foundation/AppKit) types frequently used by CoreML.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
pyobjc-framework-coreml — pip install pyobjc-framework-coreml · libregistry