PyObjC StoreKit Framework
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
- breaking PyObjC version 12.0 dropped support for Python 3.9, and version 11.0 dropped support for Python 3.8. Ensure your project uses Python 3.10 or later for `pyobjc-framework-storekit` 12.x.
- breaking Starting with PyObjC 11.1, the core bridge's behavior for Objective-C initializer methods aligns with `clang`'s Automatic Reference Counting (ARC) documentation. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference. This might affect custom memory management patterns or interactions with C/Objective-C code directly.
- gotcha The StoreKit framework is primarily designed for applications distributed through the Mac App Store and requires code signing by Apple. Developing with StoreKit outside of this context (e.g., for standalone scripts or non-App Store distribution) is severely limited or impossible.
- gotcha PyObjC 10.3 initially removed support for calling `__init__` when a user-defined `__new__` was present, breaking some projects. Version 10.3.1 reintroduced the ability to use `__init__` in such cases, but only if the class or a superclass explicitly implements `__new__`. If you rely on PyObjC's default `__new__`, `__init__` cannot be used.
- gotcha Experimental support for Python 3.13's free-threading (PEP 703) was introduced in PyObjC 11.0. However, PyObjC 10.3 explicitly stated it did not support free-threading. While there's experimental support, caution is advised, and stability with free-threading may still be evolving.
Install
-
pip install pyobjc-framework-storekit
Imports
- StoreKit
import StoreKit
Quickstart
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()