Quickstart
Go from zero to a working Python extension in 60 seconds.
1. Install the CLI
2. Create a project
This generates:
myproject/
├── pyproject.toml
├── myproject/
│ ├── __init__.py
│ └── examples/demo.py
└── swift/
├── Package.swift
└── Sources/MyProject/MyProject.swift
3. Build & install
This compiles the Swift code and installs the package into your current Python environment.
4. Use it
Or from a Python REPL:
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:
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
What's next?
- Getting Started — deeper walkthrough with classes, enums, and error handling
- Macros Reference — all available macros
- Examples — real-world packages using Apple frameworks