PyObjC ShazamKit Framework
PyObjC-framework-shazamkit provides Python bindings for Apple's ShazamKit framework on macOS, allowing Python applications to identify music and audio using Shazam's technology. It's part of the larger PyObjC project, which offers comprehensive access to macOS frameworks. The current version is 12.1, with releases typically tied to macOS SDK updates and Python version support changes.
Warnings
- breaking PyObjC has consistently dropped support for older Python versions. Version 12.0 dropped Python 3.9, and 11.0 dropped Python 3.8. Ensure your Python version meets the `requires_python` spec (currently `>=3.10`).
- gotcha PyObjC does not fully support experimental free-threading (PEP 703) in Python 3.13, despite binary wheels being available. This can lead to unexpected behavior or performance issues if free-threading is enabled and used with PyObjC components.
- breaking Behavioral changes to `__init__` and `__new__` for Python subclasses of Objective-C classes were introduced in PyObjC v10.3 and partially reverted in v10.3.1. Custom instantiation logic might break.
- breaking Automatic Reference Counting (ARC) behavior for initializer methods (`init`-family methods) was aligned with `clang` documentation in v11.1. This means PyObjC now correctly models that `init` methods steal a reference to `self` and return a new one.
- gotcha PyObjC framework packages like `pyobjc-framework-shazamkit` are macOS-specific and require a compatible macOS version and Xcode SDK. They will not work on other operating systems.
Install
-
pip install pyobjc-framework-shazamkit
Imports
- SHSession
from ShazamKit import SHSession
- SHMediaItem
from ShazamKit import SHMediaItem
- SHSignature
from ShazamKit import SHSignature
Quickstart
import platform
from ShazamKit import SHMediaItem, SHErrorDomain, SHSession
if platform.system() != "Darwin":
print("ShazamKit is a macOS-only framework. This code will only execute PyObjC specific parts on macOS.")
else:
try:
# Verify core PyObjC bridge and ShazamKit framework are loadable
_ = SHMediaItem # Accessing a class to ensure it's bound
_ = SHSession
error_domain = SHErrorDomain # Accessing a constant
print(f"Successfully imported ShazamKit framework on macOS.")
print(f"SHMediaItem class type: {type(SHMediaItem)}")
print(f"SHErrorDomain constant: {error_domain}")
# To use ShazamKit effectively, you would typically:
# 1. Request microphone permissions.
# 2. Create an SHSession with a custom SHSessionDelegate (inheriting from objc.retains('SHSessionDelegate')).
# 3. Capture audio and create an SHSignature.
# 4. Call session.matchSignature(signature).
# This quickstart merely confirms the library's basic availability.
except ImportError:
print("Error: ShazamKit framework not found. Ensure 'pyobjc-framework-shazamkit' is installed and you are on macOS.")
except Exception as e:
print(f"An unexpected error occurred: {e}")