Skip to main content

Foundation Models SDK for Python

Python bindings for Apple's Foundation Models framework, providing access to the on-device foundation model at the core of Apple Intelligence on macOS.

Overview

The Foundation Models SDK for Python provides a Pythonic interface to Apple's Foundation Models framework.

You can:

  • Evaluate Swift Foundation Models app features by running batch inference and analyzing results from Python
  • Perform on-device inference with the system foundation model
  • Stream real-time text generation responses
  • Use guided generation with structured output schemas and constraints
  • Get type-safe responses using Python decorators for guided generation
  • Configure custom model settings for different model options
  • Process transcripts exported from Swift apps for quality analysis

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

Contributing

This project is not yet taking contributions. Stay tuned!

Installation

pip install apple-fm-sdk

Alternatively, you can use the development install instructions below.

Documentation

Basic usage

import apple_fm_sdk as fm
import asyncio

async def main():
    # 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()

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

# Run async function
asyncio.run(main())

You can also use guided generation to ask the model to generate an object from a specific Python class marked with the generable decorator:

import apple_fm_sdk as fm

@fm.generable # This decorator signals this type be generated by a model
class Cat:
    name: str
    age:int = fm.guide("Age in years", range=(0, 20))

async def generate_cat():
    # 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()

        # Generate a response of the type Cat
        cat = await session.respond("Generate an adorable rescue cat", generating=Cat)
        print(f"Model response: {cat}")
    else:
        print(f"Foundation Models not available: {reason}")

Development Installation

If you need to modify the SDK or install from source:

  1. Get the code
git clone https://github.com/apple/python-apple-fm-sdk
cd python-apple-fm-sdk
  1. (Optional but recommended) Make a virtual environment. Install uv (or your package manager of choice) then:
uv venv
source .venv/bin/activate
  1. Install the package locally in editable mode:
uv sync
  1. After making any change, be sure to build the project again and test:
uv pip install -e .
pytest

For licensing see accompanying LICENSE file. Copyright (C) 2026 Apple Inc. All Rights Reserved.

Metadata

Release files for apple-fm-sdk 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apple-fm-sdk 0.2.2
File Size Uploaded Provenance Actions
apple_fm_sdk-0.2.2.tar.gz 112.2 kB Without provenance Details for apple_fm_sdk-0.2.2.tar.gz

Release files / apple_fm_sdk-0.2.2.tar.gz

Download URL apple_fm_sdk-0.2.2.tar.gz
Size 112.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b5e221e5fc25a424fdeaa579588b65e80d23261c82ad6c7a7734a206b14ef89
BLAKE2b-256 checksum
How to use checksums
a1cb2275d00b3bcf93501e68d8a76e7783280c65f8407f58fdab674b0677823c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for apple-fm-sdk 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page