Skip to content

Utilities

Platform detection and Android context helpers. These are the lowest layer the rest of the package builds on; you usually only need them if you are writing your own native handler or interop code.

Platform detection and shared helpers.

This module is imported early by most other modules, so it avoids importing platform-specific packages at module level. The detection results are cached the first time IS_ANDROID, IS_IOS, and IS_WEB are read.

Attributes:

Name Type Description
IS_ANDROID bool

True when running inside an Android process (sys.platform == "android" on the embedded CPython 3.13+, or Chaquopy's java module imports successfully).

IS_IOS bool

True when running inside an iOS app bundle (sys.platform == "ios" on the embedded CPython 3.13+, or the explicit PN_PLATFORM=ios override).

IS_WEB bool

True when running the browser preview (signaled by PN_PLATFORM=web, set by pn preview / pn start). The reconciler then commits through the bridge to a browser page instead of to Swift or Kotlin.

IS_ANDROID module-attribute

IS_ANDROID: bool = _get_is_android()

True when running inside an Android process.

The flag is computed once at import time, from sys.platform == "android" or a successful import of Chaquopy's java module.

IS_IOS module-attribute

IS_IOS: bool = _get_is_ios()

True when running inside an iOS app bundle.

The flag is computed once at import time, from sys.platform == "ios" or the explicit PN_PLATFORM=ios override.

IS_WEB module-attribute

IS_WEB: bool = _get_is_web()

True when running the browser preview.

Set by pn preview / pn start via PN_PLATFORM=web. Mutually exclusive with IS_ANDROID / IS_IOS. Off-device unit tests leave this False and inject a fake backend instead.

IS_NATIVE module-attribute

IS_NATIVE: bool = IS_ANDROID or IS_IOS or IS_WEB

True whenever the reconciler commits through the bridge.

All three of iOS, Android, and the browser preview render through a bridge transport; only headless tests have no native side at all.

Next steps