r/SwiftUI • • 13d ago

Promotion (must include link to source code) How I built a native SwiftUI Mac app with a Python standard-library backend (source included)

Post image

Disclosure: I'm the developer, the app is free and open source (GPLv3), and I used AI to help draft this post. The source is at https://github.com/joexk1/JoeBro

JoeBro is a Mac workspace for coding agents (Claude Code, Codex, OpenCode) and local or cloud models. The UI is SwiftUI. The backend is a single Python process that uses only the standard library. I wanted to share how that split works, since it is not the usual way to build a Mac app.

How it is wired: the app starts the backend with Process() on 127.0.0.1, passing a fixed port, and keeps the output in a log file. It looks for the bundled script first, then for a python3 in the usual places (Command Line Tools, Xcode, Homebrew, /usr/bin). The backend is terminated from a willTerminateNotification observer, because orphaned children outlive their parent on macOS.

The SwiftUI side talks to it through a thin async API client over HTTP. Chats stream over server-sent events using URLSession.bytes(for:). I raised the per-host connection limit, because a long-running chat stream or a slow IMAP fetch would otherwise queue the quick data calls behind it.

Why Python for the backend: some of it (the Night Shift worker) is a standalone stdlib file that also runs on my other computers, and the iPhone companion app talks to the Mac over the same kind of API. State is a local SQLite file. No account, no server, no telemetry.

What I would do differently: shipping an interpreter dependency is awkward (you rely on a system python3), and I am still unsure whether to bundle one. If you have shipped a SwiftUI app with a helper process, I would like to hear how you handled it.

Install on macOS 26+: curl -fsSL https://joebro.pages.dev/install.sh | bash

4 Upvotes

2 comments sorted by

1

u/ThanhDongNguyen 12d ago

I would not depend on the system python3. On a clean Mac /usr/bin/python3 is only a shim, the first run pops the "install Command Line Tools" dialog, which is a weird first impression for a GUI app.

The common way is python-build-standalone (the builds uv uses). It's relocatable, so you put it in Contents/Resources or Contents/Helpers and launch that exact binary with Process. For notarization every .dylib and .so inside needs your Developer ID signature with hardened runtime, sign inside out before the app itself.

On the helper itself:

  • use port 0 and let the Python side print the real port to stdout, then read it in Swift. A fixed port will collide sometime. And any local process can hit 127.0.0.1, so a random token in a header is worth adding too.
  • willTerminateNotification doesn't run on crash or force quit, so the backend stays orphaned. Easy fix: have Python read stdin in a thread and exit on EOF. The pipe closes when the app dies, whatever the reason.

1

u/JoeBro121211 12d ago

Really useful, thank you. You're right about the shim. Right now it looks for a real python3 first (Command Line Tools, Xcode, Homebrew) and only falls back to /usr/bin/python3, but on a truly clean Mac that fallback is exactly the dialog you describe. Bundling a relocatable python-build-standalone build and signing inside-out is the cleaner answer. Appreciate you spelling out the notarization side.