|
1 | | -This project leverages two different tools to integrate Python into mobile applications: |
| 1 | +# PythonNative |
2 | 2 |
|
3 | | -1. Rubicon for iOS |
4 | | -2. Chaquopy for Android |
| 3 | +**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. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Native UI Components**: Create and manage native buttons, labels, lists, and more, all from Python. |
| 8 | +- **Cross-Platform**: Write once, run on both Android and iOS. |
| 9 | +- **Lifecycle Management**: Handle app lifecycle events with ease. |
| 10 | +- **Native API Access**: Access device features like Camera, Geolocation, and Notifications. |
| 11 | +- **Powered by Proven Tools**: PythonNative integrates seamlessly with [Rubicon](https://beeware.org/project/projects/bridges/rubicon/) for iOS and [Chaquopy](https://chaquo.com/chaquopy/) for Android, ensuring robust native performance. |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### Installation |
| 16 | + |
| 17 | +First, install PythonNative via pip: |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install pythonnative |
| 21 | +``` |
| 22 | + |
| 23 | +### Create Your First App |
| 24 | + |
| 25 | +Initialize a new PythonNative app: |
| 26 | + |
| 27 | +```bash |
| 28 | +pn init my_app |
| 29 | +``` |
| 30 | + |
| 31 | +Your app directory will look like this: |
| 32 | + |
| 33 | +```text |
| 34 | +my_app/ |
| 35 | +├── README.md |
| 36 | +├── app |
| 37 | +│ ├── __init__.py |
| 38 | +│ ├── main_page.py |
| 39 | +│ └── resources |
| 40 | +├── pythonnative.json |
| 41 | +├── requirements.txt |
| 42 | +└── tests |
| 43 | +``` |
| 44 | + |
| 45 | +### Writing Views |
| 46 | + |
| 47 | +In PythonNative, everything is a view. Here's a simple example of how to create a main page with a list view: |
| 48 | + |
| 49 | +```python |
| 50 | +import pythonnative as pn |
| 51 | + |
| 52 | +class MainPage(pn.Page): |
| 53 | + def __init__(self, native_instance): |
| 54 | + super().__init__(native_instance) |
| 55 | + |
| 56 | + def on_create(self): |
| 57 | + super().on_create() |
| 58 | + stack_view = pn.StackView(self.native_instance) |
| 59 | + list_data = ["item_{}".format(i) for i in range(100)] |
| 60 | + list_view = pn.ListView(self.native_instance, list_data) |
| 61 | + stack_view.add_view(list_view) |
| 62 | + self.set_root_view(stack_view) |
| 63 | +``` |
| 64 | + |
| 65 | +### Run the app |
| 66 | + |
| 67 | +```bash |
| 68 | +pn run android |
| 69 | +pn run ios |
| 70 | +``` |
| 71 | + |
| 72 | +## Documentation |
| 73 | + |
| 74 | +For detailed guides and API references, visit the [PythonNative documentation](https://pythonnative.com/docs/introduction). |
0 commit comments