PyObjC ReplayKit Framework
pyobjc-framework-replaykit provides Python bindings for Apple's ReplayKit framework on macOS, enabling developers to integrate screen recording and broadcasting capabilities into their Python applications. Part of the larger PyObjC project, it closely tracks macOS SDK updates, with current version 12.1. The PyObjC project generally releases new versions multiple times a year, often aligning with major macOS releases and Python version updates.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Ensure your Python environment is 3.10 or newer for PyObjC 12.x.
- gotcha Starting with PyObjC 11.1, the bridge's behavior for initializer methods (like `init`) was aligned with `clang`'s Automatic Reference Counting (ARC) documentation. This means 'init' family methods now correctly steal a reference to `self` and return a new one. Code relying on the prior, less correct, reference counting behavior for initializers might need adjustment.
- gotcha In PyObjC 10.3, a change prevented the use of `__init__` when a class or its superclass utilized `__new__` provided by PyObjC. While version 10.3.1 partially re-enabled `__init__` if the user *explicitly* implemented `__new__`, `__init__` still cannot be used if the class relies on PyObjC's implicit `__new__` for Objective-C object creation.
Install
-
pip install pyobjc-framework-replaykit
Imports
- ReplayKit
import ReplayKit
Quickstart
import ReplayKit
from PyObjCTools import AppHelper
from Foundation import NSObject, NSLog
class ReplayKitChecker(NSObject):
def applicationDidFinishLaunching_(self, notification):
# Access the shared screen recorder instance
recorder = ReplayKit.RPScreenRecorder.sharedRecorder()
# Check if ReplayKit is available for recording
if recorder.isAvailable():
NSLog("ReplayKit is available for screen recording.")
else:
NSLog("ReplayKit is not available for screen recording.")
# In a real application, you'd perform further ReplayKit actions here
# For this quickstart, we just check availability and then stop the application.
AppHelper.stopEventLoop()
if __name__ == "__main__":
# Run a minimal Cocoa event loop to execute the application delegate.
# This is often necessary for PyObjC code interacting with UI frameworks.
AppHelper.runEventLoop(argv=[], appDelegate=ReplayKitChecker.alloc().init())