PyObjC ClassKit Framework
PyObjC-framework-ClassKit provides Python wrappers for the ClassKit framework on macOS, enabling Python applications to interact with educational data like assignments, activities, and progress. It is part of the broader PyObjC project, currently at version 12.1, and typically releases updates in sync with macOS SDK changes.
Warnings
- breaking Python 3.9 support was dropped in PyObjC 12.0, and Python 3.8 support was dropped in PyObjC 11.0. Ensure your Python version meets the requirements for the installed PyObjC version (e.g., PyObjC 12.x requires Python >=3.10).
- breaking PyObjC 11.1 introduced significant changes to align the core bridge's Automatic Reference Counting (ARC) behavior with `clang`'s documentation, particularly for initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new one.
- gotcha ClassKit, like all PyObjC frameworks, is specific to macOS. Code using `pyobjc-framework-classkit` will only run on macOS and requires the necessary macOS SDKs and entitlements for specific operations (e.g., accessing sensitive educational data).
- gotcha In PyObjC 10.3, the ability to use `__init__` when a user also provided `__new__` was temporarily removed, causing issues. This was reinstated in version 10.3.1. Code relying on PyObjC's provided `__new__` still cannot use `__init__`.
- breaking Older Objective-C frameworks might be removed from PyObjC bindings in newer versions if they are deprecated or removed from macOS. For example, 'IMServicePlugIn' bindings were removed in PyObjC 10.0 due to its deprecation and removal in macOS.
Install
-
pip install pyobjc-framework-classkit
Imports
- ClassKit
import ClassKit
- CLSContext
import ClassKit context = ClassKit.CLSContext.currentContext()
Quickstart
import ClassKit
from Cocoa import NSObject, NSLog # For basic logging or NSObject base
# ClassKit operations must typically be run on the main thread and
# within a macOS application context. This is a conceptual example.
# In a real app, you would interact with CLSDataStore and CLSContext.
# Get the current ClassKit context (requires user authorization and an active app)
current_context = ClassKit.CLSContext.currentContext()
if current_context:
NSLog(f"ClassKit context loaded: {current_context.title()}")
# Example: Create a new activity for the current context
# This part requires proper setup of CLSActivity, CLSActivityItem etc.
# and permissions. This is a simplified example.
# activity = ClassKit.CLSActivity()
# activity.setTitle_("My Python Activity")
# current_context.addActivity_(activity)
# ClassKit.CLSDataStore.shared().saveWithCompletion_(
# lambda success, error: NSLog(f"Activity save success: {success}, error: {error}")
# )
else:
NSLog("ClassKit context not available. Ensure app is authorized and running on macOS.")
# In a real macOS app, you might also have a PyObjC application loop running.