PythonNative is a cross-platform toolkit that allows you to create native Android and iOS apps using Python. Inspired by frameworks like React Native and NativeScript, PythonNative provides a Pythonic interface for building native UI elements, handling lifecycle events, and accessing platform-specific APIs.
- Native UI Components: Create and manage native buttons, labels, lists, and more, all from Python.
- Cross-Platform: Write once, run on both Android and iOS.
- Lifecycle Management: Handle app lifecycle events with ease.
- Native API Access: Access device features like Camera, Geolocation, and Notifications.
- Powered by Proven Tools: PythonNative integrates seamlessly with Rubicon for iOS and Chaquopy for Android, ensuring robust native performance.
First, install PythonNative via pip:
pip install pythonnative
Initialize a new PythonNative app:
pn init my_app
Your app directory will look like this:
my_app/
├── README.md
├── app
│ ├── __init__.py
│ ├── main_page.py
│ └── resources
├── pythonnative.json
├── requirements.txt
└── tests
In PythonNative, everything is a view. Here's a simple example of how to create a main page with a list view:
import pythonnative as pn
class MainPage(pn.Page):
def __init__(self, native_instance):
super().__init__(native_instance)
def on_create(self):
super().on_create()
stack_view = pn.StackView(self.native_instance)
list_data = ["item_{}".format(i) for i in range(100)]
list_view = pn.ListView(self.native_instance, list_data)
stack_view.add_view(list_view)
self.set_root_view(stack_view)
pn run android
pn run ios
For detailed guides and API references, visit the PythonNative documentation.