Skip to content

Quickstart

Go from zero to a working Python extension in 60 seconds.

1. Install the CLI

pip install applepy-cli
uv pip install applepy-cli

2. Create a project

applepy new myproject
cd myproject

This generates:

myproject/
├── pyproject.toml
├── myproject/
│   ├── __init__.py
│   └── examples/demo.py
└── swift/
    ├── Package.swift
    └── Sources/MyProject/MyProject.swift

3. Build & install

applepy develop

This compiles the Swift code and installs the package into your current Python environment.

4. Use it

python myproject/examples/demo.py
Hello, World! 🍎
Hello, ApplePy! 🍎

Or from a Python REPL:

>>> import myproject
>>> myproject.hello("World")
'Hello, World! 🍎'

5. Add your own functions

Edit swift/Sources/MyProject/MyProject.swift:

import ApplePy
@preconcurrency import ApplePyFFI

@PyFunction
func hello(name: String = "World") -> String {
    "Hello, \(name)! 🍎"
}

// Add a new function:
@PyFunction
func add(a: Int, b: Int) -> Int {
    a + b
}

// Register it in the module:
@PyModule("myproject", functions: [hello, add]) // ← add it here
func myproject() {}

Then rebuild:

applepy develop
>>> import myproject
>>> myproject.add(2, 3)
5

6. Use Apple frameworks

This is where ApplePy shines. Any Apple framework available in Swift is accessible:

import ApplePy
import NaturalLanguage
@preconcurrency import ApplePyFFI

@PyFunction
func detect_language(text: String) -> String {
    let recognizer = NLLanguageRecognizer()
    recognizer.processString(text)
    return recognizer.dominantLanguage?.rawValue ?? "unknown"
}

@PyModule("myproject", functions: [detect_language])
func myproject() {}
>>> import myproject
>>> myproject.detect_language("Bonjour le monde")
'fr'
>>> myproject.detect_language("こんにちは世界")
'ja'

7. Publish

applepy build     # → dist/myproject-0.1.0-py3-none-any.whl
applepy publish   # → uploads to PyPI

What's next?