Platform¶
The Platform class exposes runtime
information about the host platform and a select helper for writing
platform-aware code without scattering if IS_IOS / if IS_ANDROID
branches throughout the codebase.
Platform-aware constants and selectors.
A small, RN-style helper for branching app code on the host platform.
The public surface is the Platform class
exposing OS, Version, is_ios, is_android, and
select so user code can write Platform.select({"ios": ..., ...})
without importing the IS_* flags directly.
Example
Classes:
| Name | Description |
|---|---|
Platform |
Platform-aware constants and the |
Functions:
| Name | Description |
|---|---|
get_platform |
Return the active platform name. |
Platform
¶
Platform-aware constants and the select dispatcher.
All attributes are read at import time. OS is one of
"ios", "android", or "test" (the latter when running
off-device, e.g., in unit tests).
Methods:
| Name | Description |
|---|---|
select |
Pick the value matching the current platform. |
Attributes:
| Name | Type | Description |
|---|---|---|
OS |
str
|
|
Version |
str
|
Best-effort OS version string ( |
is_ios |
bool
|
|
is_android |
bool
|
|
is_test |
bool
|
|
Version
class-attribute
instance-attribute
¶
Version: str = _detect_version()
Best-effort OS version string ("17.4", "14", "python-3.11").
is_ios
class-attribute
instance-attribute
¶
True when running inside an iOS app bundle.
is_android
class-attribute
instance-attribute
¶
is_android: bool = IS_ANDROID
True when running inside an Android process.
is_test
class-attribute
instance-attribute
¶
True when running off-device (no native runtime).
select
staticmethod
¶
Pick the value matching the current platform.
Looks up spec[Platform.OS], then falls back to
spec["native"] (matches both iOS and Android), then to
spec["default"], then to the explicit default argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Dict[str, Any]
|
Mapping from platform name to value. Recognized keys:
|
required |
default
|
Any
|
Value returned when |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The matching value, or |
Quick reference¶
| Attribute | Values |
|---|---|
Platform.OS |
"ios", "android", or "test" |
Platform.Version |
Best-effort OS version string |
Platform.is_ios / Platform.is_android / Platform.is_test |
Booleans |
Platform.select(spec, default=None) |
Pick a value matching the current platform |
See also¶
- Window dimensions, safe area, keyboard hooks for reactive metric access.