PyObjC CloudKit Framework
pyobjc-framework-cloudkit provides Python wrappers for Apple's CloudKit framework on macOS, enabling Python applications to interact with iCloud services. It is part of the larger PyObjC bridge, which allows full-featured Cocoa applications to be written in pure Python. The library is currently in version 12.1 and has a sustainable release cadence.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. Users on Python 3.9 must use an earlier version of PyObjC.
- breaking PyObjC 11.0 dropped support for Python 3.8. Users on Python 3.8 must use an earlier version of PyObjC.
- breaking As of PyObjC 10.0, the 'IMServicePlugIn' framework bindings were removed. This framework was deprecated in macOS 10.13 and removed in macOS 14.
- gotcha In PyObjC 11.1, the core bridge's behavior for initializer methods (`init` family) was aligned with `clang`'s Automatic Reference Counting (ARC) documentation. This means `init` methods now correctly model stealing a reference to `self` and returning a new reference, which might change behavior for code relying on previous reference counting assumptions.
- gotcha CloudKit is an AppStore-only API and requires a developer certificate and specific entitlements configured in an Xcode project (e.g., in `Info.plist`) to function correctly. Python scripts interacting with CloudKit must be part of a properly signed and entitled macOS application bundle.
- gotcha While PyObjC 11.0 and later may include experimental support for PEP 703 (free-threading) with Python 3.13, PyObjC does not fully support the experimental free-threading features in Python 3.13 at this time. Using free-threading with PyObjC may lead to undefined behavior or crashes.
Install
-
pip install pyobjc-framework-cloudkit
Imports
- CKContainer
from CloudKit import CKContainer
Quickstart
import objc
from Foundation import NSObject
from CloudKit import CKContainer, CKRecord
# CloudKit APIs generally require an app with appropriate entitlements and a developer certificate.
# This is a minimal example showing how to access a CloudKit class.
# To run successfully, this code needs to be part of a macOS app bundle
# with CloudKit entitlements enabled.
def get_default_container_name():
try:
# Access the default CloudKit container
default_container = CKContainer.defaultContainer()
print(f"Accessed default CKContainer: {default_container}")
# Example: Getting the container identifier (CKContainerIdentifier is a string)
print(f"Default container identifier: {default_container.containerIdentifier()}")
# Instantiate a CKRecord (example, won't be saved without proper setup)
record = CKRecord.alloc().initWithRecordType_('MyCustomRecordType')
print(f"Created CKRecord: {record.recordType()}")
except objc.nosuchmethod_error as e:
print(f"Error: CloudKit method not found or framework not available. {e}")
print("Ensure you are running on macOS and have the necessary Xcode command-line tools and app entitlements.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if __name__ == '__main__':
get_default_container_name()