Foundation Models SDK for Python Documentation#

Platform Support: macOS

Python Version: 3.10+

Python bindings for Apple’s Foundation Models framework give you access to the on-device foundation model at the core of Apple Intelligence on macOS. You can use this Python SDK to evaluate your Swift app’s Foundation Models features, using Python’s rich ecosystem of tools and libraries for data and machine learning. These Python bindings run the Apple’s Foundation Models framework in Swift under the hood, so you can be confident that your evaluations reflect real on-device performance and behavior.

Keep in mind that it’s your responsibility to design AI experiences with care. To learn about practical strategies you can implement in code, check out: Improving the safety of generative model output and Apple’s Human Interface Guidelines on Generative AI.

Requirements#

Since this SDK calls the on-device foundation model at the core of Apple Intelligence it requires:

Quick Start#

Installation#

Foundation Models SDK for Python is currently in Beta. Use the development installation:

  1. Ensure you have met the requirements above.

  2. Clone the repository and navigate to the project directory:

git clone https://github.com/apple/python-apple-fm-sdk
cd python-apple-fm-sdk
  1. Create a virtual environment (uv recommended) and activate it:

uv venv
source .venv/bin/activate
  1. Install the package locally in editable mode:

uv pip install -e .

Basic Usage#

import apple_fm_sdk as fm

# Get the default system foundation model
model = fm.SystemLanguageModel()

# Check if the model is available
is_available, reason = model.is_available()
if is_available:
    # Create a session
    session = fm.LanguageModelSession(model=model)

    # Generate a response
    response = await session.respond(prompt="Hello, how are you?")
    print(f"Model response: {response}")
else:
    print(f"Foundation Models not available: {reason}")

Documentation Contents#

Indices and tables#