{"id":6115,"library":"pyobjc-framework-inputmethodkit","title":"PyObjC InputMethodKit Framework","description":"PyObjC-framework-InputMethodKit provides Python wrappers for Apple's InputMethodKit framework on macOS, allowing developers to create custom input methods using Python. It is part of the larger PyObjC project, which acts as a bridge between Python and Objective-C. The library is actively maintained with frequent releases, often synchronized with new macOS SDK versions and Python language updates.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","cocoa","input method","gui","apple"],"install":[{"cmd":"pip install pyobjc-framework-inputmethodkit","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This package provides the core bridge between Python and Objective-C, essential for all PyObjC framework wrappers.","package":"pyobjc-core","optional":false}],"imports":[{"note":"Bindings for the InputMethodKit framework are accessed directly via the InputMethodKit package.","symbol":"InputMethodKit","correct":"import InputMethodKit"},{"note":"Specific classes are imported from the top-level InputMethodKit package.","symbol":"IMKInputController","correct":"from InputMethodKit import IMKInputController"}],"quickstart":{"code":"import InputMethodKit\nimport objc\nfrom Foundation import NSObject, NSLog, NSBundle\n\n# Define a simple input controller, subclassing IMKInputController\nclass MyInputController(InputMethodKit.IMKInputController):\n    def init(self):\n        self = objc.super(MyInputController, self).init()\n        if self is None:\n            return None\n        NSLog(\"MyInputController initialized!\")\n        return self\n\n    def activateServer_(self, sender):\n        NSLog(\"Input Method activated!\")\n        return True\n\n    def deactivateServer_(self, sender):\n        NSLog(\"Input Method deactivated!\")\n        return True\n\n    # In a real input method, you'd implement methods like handleEvent_, keyUp_ etc.\n\ndef main():\n    # In a real Input Method, the name and bundleIdentifier are crucial\n    # and typically defined in the application's Info.plist.\n    # For this conceptual example, we use placeholders.\n    input_method_name = \"MyPyIM\"\n    # This bundle ID *must* match the bundle ID in your Info.plist\n    # for a functional Input Method application.\n    bundle_id = \"com.example.MyPyIM\"\n\n    # Create an IMKServer instance.\n    # The server manages client connections and dispatches events to input controllers.\n    server = InputMethodKit.IMKServer.alloc().initWithName_bundleIdentifier_(\n        input_method_name,\n        bundle_id\n    )\n\n    NSLog(\"IMKServer created for name: %@, bundleIdentifier: %@\", input_method_name, bundle_id)\n    NSLog(\"\\n*** IMPORTANT ***\\n\")\n    NSLog(\"To create a functional macOS Input Method, this Python script must be packaged\")\n    NSLog(\"inside a .app bundle with a correctly configured Info.plist (e.g., using py2app).\")\n    NSLog(\"This quickstart only demonstrates the basic class instantiation and setup.\")\n    \n    # A real Input Method would then typically run an AppHelper.runEventLoop()\n    # from PyObjCTools to handle events and keep the application running.\n    # For simplicity, we omit the blocking event loop here.\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates how to import the `InputMethodKit` framework and instantiate its core classes. Note that building a functional macOS Input Method requires additional setup, including creating an application bundle (e.g., via `py2app`) and configuring a proper `Info.plist` file with specific Input Method related keys. This code snippet focuses on the PyObjC API usage, not the complete application deployment."},"warnings":[{"fix":"Upgrade to Python 3.10 or newer (Python 3.10 is the minimum for PyObjC 12.x).","message":"PyObjC 12.0 dropped support for Python 3.9. While 12.1 fixed a packaging metadata issue that incorrectly allowed 3.9 installs, Python 3.9 is no longer officially supported. PyObjC 11.0 dropped support for Python 3.8.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom `alloc`/`init` patterns for ARC correctness. PyObjC now correctly models `init` methods stealing and returning references.","message":"PyObjC 11.1 introduced a significant change in how PyObjC models Automatic Reference Counting (ARC) for initializer methods, aligning with `clang`'s documentation. This means methods in the 'init' family now correctly steal a reference to `self` and return a new reference, which might affect custom object allocation and initialization patterns if not handled correctly.","severity":"breaking","affected_versions":">=11.1"},{"fix":"If stability is critical, avoid using PyObjC with free-threading enabled in Python 3.13. Monitor PyObjC release notes for full free-threading support.","message":"PyObjC 11.0 introduced experimental support for Python 3.13's free-threading (PEP 703), but the PyObjC project explicitly states that it does *not fully support* free-threading at this time. Using PyObjC in a free-threaded Python 3.13 environment might lead to unexpected behavior or crashes.","severity":"gotcha","affected_versions":">=11.0 (with Python 3.13)"},{"fix":"Ensure you have the latest Xcode or Command Line Tools installed for your macOS version, or an SDK compatible with the PyObjC version you are building.","message":"Building PyObjC from source (e.g., for development or specific environments) requires Xcode or the Xcode Command Line Tools to be installed, along with a suitable macOS SDK. Using an older SDK than the one specified by the PyObjC release can lead to build errors.","severity":"gotcha","affected_versions":"All versions (when building from source)"},{"fix":"Refer to Apple's InputMethodKit documentation on the Apple Developer website for API specifics when using `InputMethodKit` with PyObjC.","message":"PyObjC framework wrappers, including `pyobjc-framework-inputmethodkit`, do not include direct documentation for the Objective-C APIs. Developers must consult Apple's official documentation for the `InputMethodKit` framework to understand its classes, methods, and protocols.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}