Skip to content
Back to search

mlx-swift

Swift API for MLX

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/ml-explore/mlx-swift with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/ml-explore/mlx-swift'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/ml-explore--mlx-swift/badge.svg)](/listings/ml-explore--mlx-swift)

HTML

<a href="/listings/ml-explore--mlx-swift"><img src="/api/listings/ml-explore--mlx-swift/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

The ``MLX`` Swift package can be built and run from Xcode or SwiftPM. A CMake installation is also provided, featuring a native Linux build option.

More details are in the [documentation](https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx/install).

Xcode (1)

In Xcode you can add `https://github.com/ml-explore/mlx-swift.git` as a package dependency and link `MLX`, `MLXNN`, `MLXOptimizers` and `MLXRandom` as needed.

XCode (2)

Note that the SwiftPM and XCode (1) methods build `MLX` as a Library, not as a framework. It is possible to construct a situation where YourApp -> MLX, YourApp -> YourFramework and YourFramework -> MLX. This would give two copies of MLX in the resulting process and it may not work as expected.

If this cannot be avoided, either by making YourFramework a Library or having YourApp _not_ link MLX, you can use the `xcode/MLX.xcodeproj` to build MLX as a _Framework_. This will require `mlx-swift` to be checked out adjacent or inside your project, possibly using git submodules, and dragging the `mlx-swift/xcode/MLX.xcodeproj` into your project. Once that is done your application can build and link MLX and related as Frameworks.

SwiftPM

To use ``MLX`` with SwiftPM you can add this to your `Package.swift`:

dependencies: [
    .package(url: "https://github.com/ml-explore/mlx-swift", from: "0.10.0")
]

and add the libraries as dependencies:

dependencies: [.product(name: "MLX", package: "mlx-swift"),
               .product(name: "MLXNN", package: "mlx-swift"),
               .product(name: "MLXOptimizers", package: "mlx-swift")]

> [!Note] > SwiftPM (command line) cannot build the Metal shaders so the ultimate build has to be done > via Xcode.

xcodebuild

**Update the submodules**

The directories `Source/Cmlx/mlx` and `Source/Cmlx/mlx-c` are sourced as submodules. Before you attempt to build the project locally, pull down the updates for those submodules:

git submodule update --init --recursive

**Use Xcode to build the binaries and metal shaders**

Although `SwiftPM` (command line) cannot build the Metal shaders, `xcodebuild` can and it can be used to do command line builds:

# build and run tests
xcodebuild test -scheme mlx-swift-Package -destination 'platform=OS X'

# build Tutorial
xcodebuild build -scheme Tutorial -destination 'platform=OS X'

CMake

(1) macOS

**Install Dependencies**

Building with CMake requires both CMake and Ninja to be installed. You can do this with [Homebrew](https://brew.sh/):

brew install cmake
brew install ninja

**Build + Run Examples**

- The examples use the Metal GPU backend by default on macOS. - Note that the CUDA GPU backend is exclusive to Linux.

mkdir -p build
cd build
cmake .. -G Ninja
ninja
./example1
./tutorial

(2) Linux

**Install Dependencies**

- To build the example binaries, install all dependencies listed in the CI [scripts](.github/scripts/). - Note: The CUDA GPU backend requires the CUDA toolkit and additional dependencies. - For Swift installation on Linux, visit [swift.org](https://www.swift.org/install/linux/).

**Build + Run Examples (CPU backend)**

On Linux, the examples use the CPU backend by default.

mkdir -p build
pushd build
cmake -DMLX_BUILD_METAL=OFF .. -G Ninja
ninja
./example1
./tutorial
popd

**Build + Run Examples (GPU CUDA backend)**

mkdir -p build
pushd build
cmake -DMLX_BUILD_METAL=OFF -DMLX_BUILD_CUDA=ON -DMLX_C_BUILD_EXAMPLES=OFF .. -G Ninja
ninja
./example1 --device gpu
./tutorial --device gpu
popd

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 202 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # MLX Swift
  2. [**Installation**](#installation) | [**Documentation**](https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx) | [**Examples**](#examples)
  3. MLX Swift is a Swift API for [MLX](https://ml-explore.github.io/mlx/build/html/index.html).
  4. MLX is an array framework for machine learning on Apple silicon. MLX Swift
  5. expands MLX to the Swift language, making research and experimentation easier
  6. on Apple silicon.
  7. [View Current Release Planning](https://github.com/ml-explore/mlx-swift/issues?q=is%3Aissue+is%3Aopen+label%3Arelease-planning) and read about [Contributing](#contributing).
  8. ## Language Models
  9. LLM and VLM implementations are available in [mlx-swift-lm](https://github.com/ml-explore/mlx-swift-lm).
  10. ## Examples
  11. MLX Swift has [many
  12. examples](https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx/examples),
  13. including:
  14. - [MNISTTrainer](https://github.com/ml-explore/mlx-swift-examples/blob/main/Applications/MNISTTrainer/README.md): An example that runs on
  15. both iOS and macOS that downloads MNIST training data and trains a
  16. [LeNet](https://en.wikipedia.org/wiki/LeNet).
  17. - [MLXChatExample](https://github.com/ml-explore/mlx-swift-examples/blob/main/Applications/MLXChatExample/README.md): An example chat app that runs on both iOS and macOS that supports LLMs and VLMs.
  18. - [LLMEval](https://github.com/ml-explore/mlx-swift-examples/blob/main/Applications/LLMEval/README.md): A simple example that runs on both iOS
  19. and macOS that downloads an LLM and tokenizer from Hugging Face and
  20. generates text from a given prompt.
  21. - [StableDiffusionExample](https://github.com/ml-explore/mlx-swift-examples/blob/main/Applications/StableDiffusionExample/README.md): An
  22. example that runs on both iOS and macOS that downloads a stable diffusion model
  23. from Hugging Face and generates an image from a given prompt.
  24. - [llm-tool](https://github.com/ml-explore/mlx-swift-examples/blob/main/Tools/llm-tool/README.md): A command line tool for generating text
  25. using a variety of LLMs available on the Hugging Face hub.
  26. The [MLX Swift Examples repo](https://github.com/ml-explore/mlx-swift-examples)
  27. contains the complete code and documentation for these examples, including
  28. [guidelines on porting models](https://swiftpackageindex.com/ml-explore/mlx-swift-examples/main/documentation/mlxlmcommon/porting)
  29. from MLX Python.
  30. ## Installation
  31. The ``MLX`` Swift package can be built and run from Xcode or SwiftPM. A CMake installation is also provided, featuring a native Linux build option.
  32. More details are in the [documentation](https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx/install).
  33. ### Xcode (1)
  34. In Xcode you can add `https://github.com/ml-explore/mlx-swift.git` as a package
  35. dependency and link `MLX`, `MLXNN`, `MLXOptimizers` and `MLXRandom` as needed.
  36. ### XCode (2)
  37. Note that the SwiftPM and XCode (1) methods build `MLX` as a Library, not as a framework.
  38. It is possible to construct a situation where YourApp -> MLX, YourApp -> YourFramework
  39. and YourFramework -> MLX. This would give two copies of MLX in the resulting process
  40. and it may not work as expected.
  41. If this cannot be avoided, either by making YourFramework a Library or having YourApp
  42. _not_ link MLX, you can use the `xcode/MLX.xcodeproj` to build MLX as a _Framework_.
  43. This will require `mlx-swift` to be checked out adjacent or inside your project,
  44. possibly using git submodules, and dragging the `mlx-swift/xcode/MLX.xcodeproj` into
  45. your project. Once that is done your application can build and link MLX and related
  46. as Frameworks.
  47. ### SwiftPM
  48. To use ``MLX`` with SwiftPM you can add this to your `Package.swift`:
  49. ```swift
  50. dependencies: [
  51. .package(url: "https://github.com/ml-explore/mlx-swift", from: "0.10.0")
  52. ]
  53. ```
  54. and add the libraries as dependencies:
  55. ```swift
  56. dependencies: [.product(name: "MLX", package: "mlx-swift"),
  57. .product(name: "MLXNN", package: "mlx-swift"),
  58. .product(name: "MLXOptimizers", package: "mlx-swift")]
  59. ```
  60. > [!Note]
  61. > SwiftPM (command line) cannot build the Metal shaders so the ultimate build has to be done
  62. > via Xcode.
  63. ### xcodebuild
  64. **Update the submodules**
  65. The directories `Source/Cmlx/mlx` and `Source/Cmlx/mlx-c` are sourced as submodules.
  66. Before you attempt to build the project locally, pull down the updates for those submodules:
  67. ```shell
  68. git submodule update --init --recursive
  69. ```
  70. **Use Xcode to build the binaries and metal shaders**
  71. Although `SwiftPM` (command line) cannot build the Metal shaders, `xcodebuild` can and
  72. it can be used to do command line builds:
  73. ```shell
  74. # build and run tests
  75. xcodebuild test -scheme mlx-swift-Package -destination 'platform=OS X'
  76. # build Tutorial
  77. xcodebuild build -scheme Tutorial -destination 'platform=OS X'
  78. ```
  79. ### CMake
  80. #### (1) macOS
  81. **Install Dependencies**
  82. Building with CMake requires both CMake and Ninja to be installed. You can do
  83. this with [Homebrew](https://brew.sh/):
  84. ```shell
  85. brew install cmake
  86. brew install ninja
  87. ```
  88. **Build + Run Examples**
  89. - The examples use the Metal GPU backend by default on macOS.
  90. - Note that the CUDA GPU backend is exclusive to Linux.
  91. ```shell
  92. mkdir -p build
  93. cd build
  94. cmake .. -G Ninja
  95. ninja
  96. ./example1
  97. ./tutorial
  98. ```
  99. #### (2) Linux
  100. **Install Dependencies**
  101. - To build the example binaries, install all dependencies listed in the CI [scripts](.github/scripts/).
  102. - Note: The CUDA GPU backend requires the CUDA toolkit and additional dependencies.
  103. - For Swift installation on Linux, visit [swift.org](https://www.swift.org/install/linux/).
  104. **Build + Run Examples (CPU backend)**
  105. On Linux, the examples use the CPU backend by default.
  106. ```shell
  107. mkdir -p build
  108. pushd build
  109. cmake -DMLX_BUILD_METAL=OFF .. -G Ninja
  110. ninja
  111. ./example1
  112. ./tutorial
  113. popd
  114. ```
  115. **Build + Run Examples (GPU CUDA backend)**
  116. ```shell
  117. mkdir -p build
  118. pushd build
  119. cmake -DMLX_BUILD_METAL=OFF -DMLX_BUILD_CUDA=ON -DMLX_C_BUILD_EXAMPLES=OFF .. -G Ninja
  120. ninja
  121. ./example1 --device gpu
  122. ./tutorial --device gpu
  123. popd
  124. ```
  125. ## Contributing
  126. Check out the [contribution guidelines](CONTRIBUTING.md) for more information
  127. on contributing to MLX. See the
  128. [docs](https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx/install) for more
  129. information on building from source, and running tests.
  130. We are grateful for all of [our
  131. contributors](ACKNOWLEDGMENTS.md#Individual-Contributors). If you contribute
  132. to MLX Swift and wish to be acknowledged, please add your name to the list in your
  133. pull request.
  134. Smaller, focused PRs are easier and quicker to review. Sometimes larger PRs can't be helped. If you want to discuss, feel free to open an issue or ask questions in a PR.
  135. MLX Swift was initially developed by David Koski and Ronan Collobert, and is
  136. now maintained by David Koski. MLX Swift is built on top of
  137. [MLX](https://github.com/ml-explore/mlx), which was initially developed with
  138. equal contribution by Awni Hannun, Jagrit Digani, Angelos Katharopoulos, and
  139. Ronan Collobert.
  140. ## Versions
  141. See [Releases](https://github.com/ml-explore/mlx-swift/releases). Generally the MLX Swift version number corresponds to the same version number in [MLX](https://github.com/ml-explore/mlx). Release notes indicate specifics.
  142. All capabilities in MLX (Python) should be available in MLX Swift. If you encounter any that are missing please file an issue or feel free to submit a PR.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.