Package overview¶
PythonNative re-exports a small public surface from
pythonnative/__init__.py. Most user code only ever touches the names
in this overview; deeper internals (reconciler, native_views,
hosts) are documented for contributors and integrators.
Entry point¶
Your app module defines a top-level component named App:
import pythonnative as pn
@pn.component
def HomeScreen() -> pn.Node:
return pn.Text("Hello from PythonNative")
Root = pn.StackNavigator(HomeScreen)
@pn.component
def App() -> pn.Node:
return pn.NavigationContainer(Root)
The bundled Android ScreenFragment and iOS ViewController load
your app by module path ("app.main") and look up the
module's top-level App attribute. There is no registration step
or imperative bootstrap call. If you need to expose a
differently-named root component, configure the templates to load
an explicit dotted path like "app.main.RootScreen" instead.
PythonNative: declarative native UI for Android and iOS.
PythonNative is a cross-platform toolkit that turns Python @component
functions into real, native Android and iOS views. The component model
is React-like (function components plus hooks). Python owns the logical
component tree and reconciliation on a dedicated asyncio application thread.
Versioned commits cross into Swift PythonNativeKit on iOS and the Kotlin
pythonnative module on Android. Those renderers own widgets, Yoga layout,
measurement, gestures, and animation frames on the platform UI thread.
The browser preview uses DOM widgets and Yoga WebAssembly.
Key building blocks:
- Element factories (
Text,Button,Column, etc.) return immutableElementdescriptors. - Hooks (
use_state,use_effect,use_reducer, etc.) manage state, side effects, and context inside@componentfunctions. - Navigation: screens are components whose parameters are their
route params, listed in module-level
StackNavigator,TabNavigator, orDrawerNavigatorvalues and rendered byNavigationContainer.nav.push(ItemScreen(id=42))is checked by the type checker. - Styling uses a
styledict per element (or a list of dicts), typed by theStyleTypedDict.StyleSheetnamespaces group named styles, and oneThemestyles the app and its navigators. - State lives in hooks for a component and in a typed
Storefor the app. - Animations use the
Animatednamespace. Serialized graphs connect values, arithmetic, interpolation, and style bindings. Native timing, spring, decay, scroll, and gesture drivers update supported bindings without Python work on every frame. - Gestures attach to any view via the
gestures=prop using descriptors frompythonnative.gestures(Tap,LongPress,Pan,Swipe,Pinch,Rotation). - Custom native components can be authored with the
pythonnative.sdkpackage: define a typedPropsdataclass and declare the component withdefine_component, which returns its element factory (or expose it from a PyPI package via thepythonnative.handlersentry-point group).
Example
Where to look next¶
The reference is split per module so each page stays scannable:
Property reference¶
All visual and layout properties pass through the style dict (or a
list of dicts). The full per-component property catalogue lives in
Component properties.