PyObjC PassKit Framework
pyobjc-framework-passkit provides Python bindings for Apple's PassKit framework on macOS, enabling Python applications to interact with Wallet passes. It is part of the larger PyObjC project, offering direct access to the native macOS APIs. Version 12.1 is current, with releases typically synchronized with new macOS SDKs and PyObjC core updates.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. Users on Python 3.9 or older must upgrade their Python version to use `pyobjc-framework-passkit` 12.0 or newer.
- breaking PyObjC 11.0 dropped support for Python 3.8. Users on Python 3.8 must upgrade their Python version to use `pyobjc-framework-passkit` 11.0 or newer.
- breaking PyObjC 11.1 changed the behavior of 'init' family methods and `NSObject.alloc()` to align with Objective-C's Automatic Reference Counting (ARC) specification. This change affects how references are handled for newly initialized objects and might require reviewing code that manually manages object lifecycle or uses `alloc()` followed by `init` methods.
- gotcha After PyObjC 10.3, if a Python class subclasses an Objective-C class and relies on PyObjC's default `__new__` implementation (i.e., doesn't define its own `__new__`), it cannot implement `__init__`. While PyObjC 10.3.1 partially reverted this for classes with user-implemented `__new__`, the general rule for relying on PyObjC's `__new__` is to avoid Python `__init__` on those subclasses.
Install
-
pip install pyobjc-framework-passkit
Imports
- PassKit
import PassKit
- PKPassLibrary
import PassKit pass_library = PassKit.PKPassLibrary.sharedPassLibrary()
Quickstart
import PassKit
import objc
def check_passkit_availability():
if PassKit.PKPassLibrary.isPassLibraryAvailable():
print("PassKit library is available on this system.")
pass_library = PassKit.PKPassLibrary.sharedPassLibrary()
print(f"Shared Pass Library object: {pass_library}")
# Note: Interacting with passes (e.g., listing, adding) often requires
# your Python script to be bundled as a properly signed macOS application
# with specific entitlements.
# Attempting to fetch passes in a non-entitled script might result in empty lists or errors.
# Example: Check if the current app is allowed to add passes
if pass_library.canAddPasses():
print("This application is authorized to add passes to Wallet.")
else:
print("This application is not authorized to add passes to Wallet.")
else:
print("PassKit library is not available on this system.")
if __name__ == "__main__":
check_passkit_availability()