pip install pythonnative
pn --helppn init MyAppThis scaffolds:
app/with a minimalmain_page.pypythonnative.jsonproject configrequirements.txt.gitignore
A minimal app/main_page.py looks like:
import pythonnative as pn
@pn.component
def App():
count, set_count = pn.use_state(0)
return pn.Column(
pn.Text(f"Count: {count}", style={"font_size": 24}),
pn.Button(
"Tap me",
on_click=lambda: set_count(count + 1),
),
style={"spacing": 12, "padding": 16},
)Key ideas:
@pn.componentmarks a function as a PythonNative component. The function returns an element tree describing the UI. PythonNative creates and updates native views automatically.pn.use_state(initial)creates local component state. Call the setter to update it — the UI re-renders automatically.style={...}passes visual and layout properties as a dict (or list of dicts) to any component.- Element functions like
pn.Text(...),pn.Button(...),pn.Column(...)create lightweight descriptions, not native objects.
pn run android
# or
pn run ios- Uses bundled templates (no network required for scaffolding)
- Copies your
app/into the generated project
If you just want to scaffold the platform project without building, use:
pn run android --prepare-only
pn run ios --prepare-onlyThis stages files under build/ so you can open them in Android Studio or Xcode.
Remove the build artifacts safely:
pn clean