PyObjC CryptoTokenKit Framework
PyObjC is a comprehensive bridge between Python and Objective-C, enabling the development of full-featured Cocoa applications entirely in Python. This specific package provides Python wrappers for Apple's CryptoTokenKit framework on macOS, allowing Python applications to interact with cryptographic tokens like smart cards and Hardware Security Modules (HSMs). The current version is 12.1, with releases typically aligning with macOS SDK updates and Python version support.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. Users on Python 3.9 must use an older version of PyObjC.
- breaking PyObjC 11.0 dropped support for Python 3.8. Users on Python 3.8 must use an older version of PyObjC.
- gotcha PyObjC 11.1 aligned its behavior for Objective-C 'init' family methods with `clang`'s automatic reference counting documentation. This means that methods in the 'init' family now correctly steal a reference to `self` and return a new reference, which may affect custom initializers written in Python.
- gotcha The interaction between Python's `__init__` and `__new__` methods changed in PyObjC 10.3, where `__init__` could not be used with PyObjC-provided `__new__`. A partial reintroduction in v10.3.1 allowed `__init__` when a user implements `__new__`, but not when relying on PyObjC's `__new__`.
- gotcha While PyObjC 11.0 and 10.3 include experimental support for free-threading (PEP 703) introduced in Python 3.13, it does not fully support this feature. Users should be aware of potential limitations or issues when running PyObjC with a free-threaded Python interpreter.
- deprecated `objc.ObjCLazyModule` is deprecated. The lazy loading mechanism now defaults to using module-level `__dir__` and `__getattr__`. This changes how attributes are accessed and ensures private symbols from dependencies are no longer implicitly imported.
Install
-
pip install pyobjc-framework-cryptotokenkit
Imports
- CryptoTokenKit
import CryptoTokenKit
- TKTokenDriver
from CryptoTokenKit import TKTokenDriver
Quickstart
import CryptoTokenKit
# Accessing a class from the CryptoTokenKit framework
# Note: Instantiating many CryptoTokenKit classes directly in a script
# without being a proper macOS token extension might not be meaningful.
# This example primarily demonstrates successful import and class access.
token_driver_class = CryptoTokenKit.TKTokenDriver
print(f"Successfully imported CryptoTokenKit.")
print(f"TKTokenDriver is a: {type(token_driver_class)}")
print(f"Name of the TKTokenDriver class: {token_driver_class.__name__}")
# Example of attempting to access a class method (if available)
# (This specific call might not be functional without a running token service)
# if hasattr(token_driver_class, 'driverExtensionPointForIdentifier_'):
# print(f"TKTokenDriver has driverExtensionPointForIdentifier_ method.")