PyObjC CloudKit Framework

12.1 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This quickstart demonstrates how to import and interact with basic CloudKit objects like `CKContainer` and `CKRecord`. Note that CloudKit operations fundamentally require a macOS application with specific entitlements and a developer certificate to function correctly in a real-world scenario.

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()

view raw JSON →