PyObjC ARKit Framework
This library provides Python bindings for Apple's ARKit framework, enabling Python applications to leverage Augmented Reality capabilities on macOS and iOS. The current version is 12.1, with releases typically tied to macOS SDK updates, introducing major versions for new macOS support and minor versions for bug fixes and incremental SDK changes.
Warnings
- breaking The ARKit framework bindings were first introduced in PyObjC version 12.0. If your project targets an older PyObjC version (e.g., 11.x or prior), the `ARKit` framework will not be available.
- breaking PyObjC 12.0 dropped support for Python 3.9. Users must ensure their Python environment is running Python 3.10 or a newer version.
- gotcha PyObjC and its framework wrappers, including `pyobjc-framework-arkit`, are exclusively for macOS and iOS (via cross-compilation tools like BeeWare). This library cannot be used on Windows, Linux, or other non-Apple operating systems.
- gotcha Starting with PyObjC 11.1, the core bridge's Automatic Reference Counting (ARC) behavior for Objective-C `init` methods was aligned more strictly with `clang`'s documentation. `init` methods now correctly 'steal' a reference to `self` and return a new one. This change might subtly affect object lifecycle and memory management, especially if you have custom `init` implementations or rely on previous PyObjC behavior.
- gotcha PyObjC currently does not support the experimental free-threading (PEP 703) introduced in Python 3.13. Running PyObjC with free-threading enabled in Python 3.13 may lead to undefined behavior, crashes, or incorrect functionality.
Install
-
pip install pyobjc-framework-arkit
Imports
- ARSession
from ARKit import ARSession
- ARWorldTrackingConfiguration
from ARKit import ARWorldTrackingConfiguration
Quickstart
import objc
from ARKit import ARSession, ARWorldTrackingConfiguration
from Foundation import NSObject # Useful for general Cocoa classes
# ARKit is a macOS/iOS framework, so check for its presence
if not objc.is_defined('ARSession'):
print("ARKit framework is not available on this system or macOS version.")
else:
print("ARKit framework is available.")
# Allocate and initialize an ARSession
session = ARSession.alloc().init()
print(f"Created ARSession object: {session}")
# Create a configuration for the session
config = ARWorldTrackingConfiguration.new()
print(f"Created ARWorldTrackingConfiguration object: {config}")
# Check if ARSession is supported on the device
is_supported = ARSession.isSupported()
print(f"ARSession.isSupported(): {is_supported}")
# In a full application, you would run the session like this:
# session.runWithConfiguration_(config)
# print("ARSession started.")