PyObjC StoreKit Framework

12.1 · active · verified Tue Apr 14

PyObjC is a bridge between Python and Objective-C, allowing Python scripts to use and extend macOS frameworks. `pyobjc-framework-storekit` provides Python wrappers for Apple's StoreKit framework, enabling developers to integrate in-app purchases and subscriptions into macOS applications written in Python. The current version is 12.1, and the project maintains an active release cadence, frequently updating bindings for new macOS SDKs and Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `StoreKit` framework and begin observing payment queue transactions. Note that a fully functional StoreKit implementation requires a running macOS Cocoa application context, proper provisioning profiles, and an application distributed through the Mac App Store. The `AppHelper.runEventLoop()` call, commented out here, is essential for a complete PyObjC GUI application to process events.

import objc
from Foundation import NSObject
from StoreKit import SKPaymentQueue
from PyObjCTools import AppHelper

class StoreKitDelegate(NSObject):
    def paymentQueue_updatedTransactions_(self, queue, transactions):
        for transaction in transactions:
            print(f"Transaction State: {transaction.transactionState}, Product ID: {transaction.payment.productIdentifier}")

    # Other delegate methods would go here, e.g., for purchase failures, restores, etc.

def main():
    print("Initializing StoreKit components...")
    # Obtain the default payment queue
    queue = SKPaymentQueue.defaultQueue()

    # Create and set a delegate (critical for handling transaction updates)
    delegate = StoreKitDelegate.alloc().init()
    queue.addTransactionObserver_(delegate)

    print("StoreKit observation started. This requires a running Cocoa event loop.")
    print("To actually initiate purchases, you would call queue.addPayment_(SKPayment.paymentWithProduct_)")
    print("Note: Full StoreKit functionality requires an application signed by Apple and distributed via the Mac App Store.")
    # In a real app, AppHelper.runEventLoop() would be called, typically after setting up the GUI
    # AppHelper.runEventLoop() 

if __name__ == '__main__':
    main()

view raw JSON →