🍎 ApplePy
Create native Python extensions in Swift.
ApplePy lets you build pip install-able Python packages written entirely in Swift — with direct access to Apple frameworks like CoreML, Metal, NaturalLanguage, Security, and more.
-
Get started in 30 seconds
-
Write Swift, import from Python
-
Access Apple frameworks
CoreML, Metal, NaturalLanguage, Security — any framework available in Swift is now available from Python.
-
pip install & publish
Build wheels, publish to PyPI. Your users just
pip install— no Swift toolchain needed at runtime.
Quick Example
Features
| Macro | Purpose |
|---|---|
@PyFunction |
Expose top-level functions (with default argument support) |
@PyClass |
Expose structs/classes as Python types |
@PyMethod |
Mark instance methods for Python |
@PyStaticMethod |
Mark static methods for Python |
@PyProperty |
Expose stored properties with getters/setters |
@PyEnum |
Swift enum → Python IntEnum or class hierarchy |
@PyModule |
Generate PyInit_ module entry point |
Type Conversions
| Swift | Python | Direction |
|---|---|---|
Int, Double, Float, Bool |
int, float, bool |
↔ |
String |
str |
↔ |
[T] |
list |
↔ |
[K: V] |
dict |
↔ |
Set<T> |
set |
↔ |
Optional<T> |
None / value |
↔ |
PyTuple2<A,B>, PyTuple3<A,B,C> |
tuple |
↔ |
vs PyO3
| Dimension | PyO3 (Rust) | ApplePy (Swift) |
|---|---|---|
| Macros | #[pyfunction], #[pyclass] |
@PyFunction, @PyClass |
| Memory safety | 'py lifetimes |
GILGuard: ~Copyable |
| Build tool | maturin |
applepy CLI |
| Platform | Cross-platform | macOS (Apple frameworks) |
| Enums | Class-based | IntEnum + class hierarchy |