Skip to main content

djust-mobile-toga

Embed djust as an on-device loopback server inside a Toga + Briefcase mobile app. Extracted from a working reference app that runs the same Django + djust codebase on iOS Simulator and Android emulator with no remote backend.

The core three pieces:

Module What it does
djust_mobile_toga.shims Cross-platform compatibility shims (must run BEFORE importing uvicorn/Django).
djust_mobile_toga.serve Loopback-bound uvicorn helper that bypasses uvicorn.supervisors (iOS Python lacks _multiprocessing).
djust_mobile_toga.app BaseDjustApp(toga.App) — handles writable data dir, background-thread Django prep, uvicorn boot, WebView.

…plus optional, fail-soft native bridges — bridge (JS↔Python), passkit (Apple Wallet), voice (on-device STT/TTS), apple_intelligence (Foundation Models), notifications. See docs/native-bridges.md.

Status

Beta. Typed (py.typed), CI-gated (ruff + mypy + pytest on py3.11–3.13), and tested — the core (serve/shims/apps/templatetags/bridge) is at ~100% off-device coverage; the iOS/Android native bodies are hand-verified on a device (see docs/platform-support.md). The public API is stabilizing but may still evolve before a 1.0; pin a version.

Documentation

Quick start

# myapp/__main__.py
from djust_mobile_toga.app import BaseDjustApp


class MyApp(BaseDjustApp):
    asgi_app_path = "myapp.asgi:application"
    django_settings_module = "myapp.settings"
    status_bar_color_argb = 0xFF14457E  # opaque blue; remove for system default

    def on_app_ready(self):
        # Optional post-launch hook (notifications, analytics, etc.).
        pass


def main():
    return MyApp(
        formal_name="My App",
        app_id="org.example.myapp",
        app_name="myapp",
    )


if __name__ == "__main__":
    main().main_loop()

Then in your Toga app entry point (__main__.py for Briefcase), make sure the shims install BEFORE anything else imports uvicorn/Django:

from djust_mobile_toga import shims
shims.install()                   # CALL FIRST

from myapp.app import main
main().main_loop()

What's still on you (the consumer)

This package handles the runtime glue. The consumer is responsible for:

  1. Cross-compiling djust for iOS (aarch64-apple-ios, aarch64-apple-ios-sim) and/or Android (aarch64-linux-android, x86_64-linux-android). djust itself doesn't currently publish mobile wheels; the reference recipe is maturin + a BeeWare cross-platform venv for iOS, and cibuildwheel --platform android for Android (which manages the NDK download itself).

  2. Repackaging non-mobile native depsmsgpack ships a pure-Python fallback that needs to be re-tagged with iOS/Android platform tags so pip will install it under --platform. A small script that walks an installed package's __init__.py, strips compiled .so files, and emits a py3-none-ios_..._iphoneos.whl / …_android_21_arm64_v8a.whl is enough.

  3. Briefcase scaffold patches — at least on Android, the generated pip-options.txt needs an absolute path for --find-links wheels and the theme colorPrimaryDark in res/values/colors.xml needs to match status_bar_color_argb (the activity theme paints the status bar before any runtime setStatusBarColor call lands).

  4. POST_NOTIFICATIONS permission on Android 13+ if using djust_mobile_toga.notifications — declare it in your Briefcase [tool.briefcase.app.<name>.android] block as permission."android.permission.POST_NOTIFICATIONS" = "...". Without it the system silently drops notifications.

  5. Settings module that respects DJUST_MOBILE_DATA_DIR — your Django settings.py reads this env var (set by BaseDjustApp at startup) to place SQLite + collected static files somewhere writable.

License

MIT.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djust_mobile_toga-0.6.0.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djust_mobile_toga-0.6.0-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

Details for the file djust_mobile_toga-0.6.0.tar.gz.

File metadata

  • Download URL: djust_mobile_toga-0.6.0.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for djust_mobile_toga-0.6.0.tar.gz
Algorithm Hash digest
SHA256 9ecfbf93f9a59009ac85274a7b83200bb0ac09fcbe226b2d2dacce9ab2ca5c4f
MD5 82e9656107820c3e16aa66b0cf69d21f
BLAKE2b-256 673c8f3f6b61fa0eb30d9ae3a49d09dc61522cd96b325e3920350bd28ca1bffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for djust_mobile_toga-0.6.0.tar.gz:

Publisher: release.yml on djust-org/djust-mobile-toga

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file djust_mobile_toga-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djust_mobile_toga-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 685f37630f91c62ca809ccc8c900bbfa014a0889844fb831ab6d3be42c3aa9c2
MD5 a2dc5ad53dd34a622578f0085b7e1523
BLAKE2b-256 4b19da73f855c2283eef5a9d590ee723efb917a0b7eeb5076c63154fed3cc5ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for djust_mobile_toga-0.6.0-py3-none-any.whl:

Publisher: release.yml on djust-org/djust-mobile-toga

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page