{"id":6149,"library":"pyobjc-framework-notificationcenter","title":"PyObjC NotificationCenter Framework","description":"PyObjC-framework-NotificationCenter provides Python bindings for Apple's NotificationCenter.framework on macOS, allowing Python applications to interact with the system's user notification services. It primarily wraps the older NSUserNotification API. As part of the larger PyObjC project, it maintains an active development pace, with releases often coinciding with new macOS SDK updates, currently at version 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","pyobjc","notificationcenter","gui","framework","objective-c","cocoa"],"install":[{"cmd":"pip install pyobjc-framework-notificationcenter","lang":"bash","label":"Install specific framework"},{"cmd":"pip install pyobjc","lang":"bash","label":"Install all PyObjC frameworks (including this one)"}],"dependencies":[{"reason":"Core bridge for Python and Objective-C, required by all PyObjC frameworks.","package":"pyobjc-core"},{"reason":"Provides fundamental Objective-C classes (like NSObject, NSDate) from Foundation.framework, which NotificationCenter often relies on.","package":"pyobjc-framework-Cocoa"}],"imports":[{"note":"For using the NSUserNotificationCenter and NSUserNotification APIs. For newer UserNotifications.framework (macOS 10.14+), use `pyobjc-framework-UserNotifications` and import from `UserNotifications`.","symbol":"NSUserNotificationCenter, NSUserNotification","correct":"from Foundation import NSDate\nfrom NotificationCenter import NSUserNotification, NSUserNotificationCenter"}],"quickstart":{"code":"import objc\nfrom Foundation import NSDate\nfrom NotificationCenter import NSUserNotification, NSUserNotificationCenter\nimport time\n\n# Create a notification\nnotification = NSUserNotification.alloc().init()\nnotification.setTitle_(\"PyObjC Notification\")\nnotification.setInformativeText_(\"This is a test notification from NotificationCenter.framework.\")\nnotification.setDeliveryDate_(NSDate.dateWithTimeIntervalSinceNow_(0)) # Deliver immediately\n\n# Set an identifier to avoid duplicate notifications in Notification Center (optional, but good practice)\nnotification.setIdentifier_(f\"com.example.pyobjc.notification.{time.time()}\")\n\n# Get the default notification center and deliver the notification\nnotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()\nnotificationCenter.deliverNotification_(notification)\n\nprint(\"Notification delivered. Check your macOS Notification Center.\")\n# In a real application, you might need to run an event loop\n# For simple scripts, exiting is usually sufficient as the notification\n# delivery is handled by the system.\n","lang":"python","description":"This quickstart demonstrates how to send a simple user notification using the `NSUserNotification` and `NSUserNotificationCenter` APIs provided by `NotificationCenter.framework` on macOS. Note that for modern macOS (10.14+), Apple recommends `UserNotifications.framework` (UNUserNotificationCenter), which is available via `pyobjc-framework-UserNotifications`."},"warnings":[{"fix":"Upgrade to a supported Python version (currently >=3.10 for PyObjC 12.1) or pin an older PyObjC version compatible with your Python environment.","message":"PyObjC frequently drops support for older Python versions. Version 12.0 dropped Python 3.9, and version 11.0 dropped Python 3.8. Always verify Python compatibility for your specific PyObjC version.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom Python subclasses of Objective-C objects, especially those implementing `init` methods, to ensure correct reference handling and avoid memory leaks or crashes.","message":"Major changes to PyObjC's Automatic Reference Counting (ARC) behavior, particularly for initializer (`init`) methods. PyObjC now correctly models that methods in the 'init' family steal a reference to self and return a new reference, aligning with Clang's ARC documentation.","severity":"breaking","affected_versions":">=11.1"},{"fix":"When subclassing Objective-C classes in Python, be cautious with overriding `__new__` and `__init__`. If `__new__` is not explicitly provided by your class or its Python superclasses, use `__init__` as usual. If you override `__new__`, ensure it correctly calls the superclass's `__new__` or `alloc().init()` pattern.","message":"Interactions between Python's `__init__` and `__new__` methods and Objective-C object creation can be tricky. PyObjC 10.3 initially removed `__init__` support when PyObjC's `__new__` was used, which was partially re-introduced in 10.3.1.","severity":"gotcha","affected_versions":">=10.3"},{"fix":"If using Python 3.13, exercise caution with free-threading when using PyObjC. For critical applications, consider using a non-free-threaded Python build or waiting for more stable PyObjC free-threading support.","message":"Experimental support for Python 3.13's free-threading (PEP 703) was introduced in PyObjC 11.0, but PyObjC 10.3 explicitly did not support it. Using PyObjC in a free-threaded environment may introduce instability or unexpected behavior.","severity":"gotcha","affected_versions":">=10.3"},{"fix":"For new development or modern macOS applications, consider using `pyobjc-framework-UserNotifications` and its `UNUserNotificationCenter` API instead of `pyobjc-framework-notificationcenter`.","message":"The `NSUserNotificationCenter` API, wrapped by this framework, is deprecated on macOS 10.14 and later in favor of `UserNotifications.framework` (`UNUserNotificationCenter`). While still functional, Apple recommends migrating to the newer API for future compatibility and features.","severity":"deprecated","affected_versions":"macOS 10.14+"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}