Python to Mobile - Write mobile apps in pure Python with DSL
Project description
Python2Mobile (P2M)
Write mobile apps in pure Python with a declarative DSL. P2M generates or runs native/hybrid apps for Android, iOS, and Web.
Features
- Python DSL - Write UI and logic in familiar Python syntax
- Tailwind-like Styling - Use CSS class names for mobile styling
- Hot Reload - See changes instantly during development
- Multi-LLM Support - OpenAI, Claude, Ollama, or any OpenAI-compatible API
- Multiple Targets - Generate React Native or Flutter code
- DevServer - Preview apps in browser before building
Quick Start
pip install python2mobile
# Create a new app
p2m new myapp
cd myapp
# Run in development mode (hot reload)
p2m run
# Build for production
p2m build --target android
p2m build --target ios
p2m build --target web
Example App
from p2m.core import Render
from p2m.ui import Container, Text, Button
def click_button():
print("Button clicked!")
def create_view():
container = Container(class_="bg-gray-100 min-h-screen flex items-center justify-center")
inner = Container(class_="text-center space-y-6 p-8 bg-white rounded-2xl shadow-lg")
text = Text("Welcome to P2M", class_="text-gray-800 text-2xl font-bold")
button = Button(
"Click Me",
class_="bg-blue-600 text-white font-semibold py-3 px-8 rounded-xl hover:bg-blue-700",
on_click=click_button
)
inner.add(text).add(button)
container.add(inner)
return container.build()
def main():
Render.execute(create_view)
if __name__ == "__main__":
main()
Configuration
Create a p2m.toml file:
[project]
name = "MyApp"
version = "0.1.0"
entry = "main.py"
[build]
target = ["android", "ios", "web"]
generator = "flutter" # or "react-native"
llm_provider = "openai" # openai | anthropic | ollama | openai-compatible
llm_model = "gpt-4o"
output_dir = "./build"
cache = true
[devserver]
port = 3000
hot_reload = true
mobile_frame = true
[style]
system = "tailwind"
LLM Configuration
OpenAI
[llm.openai]
api_key = "sk-..."
model = "gpt-4o"
Claude (Anthropic)
[llm.anthropic]
api_key = "sk-ant-..."
model = "claude-3-opus-20240229"
Ollama (Local)
[llm.ollama]
base_url = "http://localhost:11434"
model = "llama2"
OpenAI Compatible
[llm.custom]
base_url = "https://api.example.com/v1"
api_key = "your-api-key"
model = "your-model-name"
x_api_key = "optional-header"
Architecture
┌─────────────────────────────────────────────────────┐
│ DEVELOPER │
│ writes in Python P2M │
└──────────────────────┬──────────────────────────────┘
│
┌────────────▼────────────┐
│ p2m CLI │
│ (p2m run / p2m build) │
└────────────┬────────────┘
│
┌─────────────┴──────────────┐
│ │
┌────▼────┐ ┌─────▼──────┐
│ p2m run │ │ p2m build │
│ (dev) │ │ (prod) │
└────┬────┘ └─────┬──────┘
│ │
┌────▼────────────┐ ┌──────▼───────────┐
│ P2M Runtime │ │ AI Code Generator│
│ - AST Parser │ │ - LLM Integration│
│ - Safe Eval │ │ - React Native │
│ - HTML Renderer │ │ - Flutter │
│ - Hot Reload │ │ - Web │
└────┬────────────┘ └──────┬───────────┘
│ │
┌────▼────────────┐ ┌──────▼───────────┐
│ Web Visualizer │ │ /build/ │
│ localhost:3000 │ │ android/ │
│ Mobile Preview │ │ ios/ │
└─────────────────┘ │ web/ │
└──────────────────┘
Project Structure
p2m/
├── __init__.py
├── cli.py # CLI entry point
├── config.py # Configuration management
├── core/
│ ├── __init__.py
│ ├── runtime.py # Python runtime engine
│ ├── ast_walker.py # AST analysis
│ ├── render_engine.py # Component tree → HTML
│ ├── hot_reload.py # File watcher
│ └── event_bridge.py # JS ↔ Python bridge
├── ui/
│ ├── __init__.py
│ ├── components.py # Base components
│ ├── layouts.py # Layout components
│ └── styles.py # Style system
├── devserver/
│ ├── __init__.py
│ ├── server.py # FastAPI server
│ ├── templates.py # Jinja2 templates
│ └── websocket_handler.py # WebSocket bridge
├── llm/
│ ├── __init__.py
│ ├── base.py # Base LLM interface
│ ├── openai_provider.py # OpenAI integration
│ ├── anthropic_provider.py # Claude integration
│ ├── ollama_provider.py # Ollama integration
│ └── factory.py # LLM factory
├── build/
│ ├── __init__.py
│ ├── generator.py # Code generator
│ ├── react_native.py # React Native templates
│ ├── flutter.py # Flutter templates
│ └── cache.py # Build cache
└── utils/
├── __init__.py
├── logger.py # Logging
└── validators.py # Validation
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python2mobile-0.1.7.tar.gz.
File metadata
- Download URL: python2mobile-0.1.7.tar.gz
- Upload date:
- Size: 109.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
929de34aeaf5a02bee86616e60ba7fc570b01759e57610bedbb413f82d2027be
|
|
| MD5 |
b3e4564badc90b84f619a869efc5b579
|
|
| BLAKE2b-256 |
b96f7693db8e6a18b213f326d1202591763ca876fec7127c668105ca5890635c
|
Provenance
The following attestation bundles were made for python2mobile-0.1.7.tar.gz:
Publisher:
publish.yml on alvaro-brito/python2mobile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python2mobile-0.1.7.tar.gz -
Subject digest:
929de34aeaf5a02bee86616e60ba7fc570b01759e57610bedbb413f82d2027be - Sigstore transparency entry: 1108173819
- Sigstore integration time:
-
Permalink:
alvaro-brito/python2mobile@e7835abc0a269b0c5e1b1a8b21733fa51b2e4288 -
Branch / Tag:
refs/tags/v0.1.7-RELEASE - Owner: https://github.com/alvaro-brito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7835abc0a269b0c5e1b1a8b21733fa51b2e4288 -
Trigger Event:
push
-
Statement type:
File details
Details for the file python2mobile-0.1.7-py3-none-any.whl.
File metadata
- Download URL: python2mobile-0.1.7-py3-none-any.whl
- Upload date:
- Size: 128.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f72569f7253dcfed847eb9491291cc551120abd00b19f2078a19452393479c00
|
|
| MD5 |
4f777da2e253484f841c99ff04f72de1
|
|
| BLAKE2b-256 |
450fab16d4c43379c7f67bb7adb8fa515c39808936d2381583f9091b55be2f09
|
Provenance
The following attestation bundles were made for python2mobile-0.1.7-py3-none-any.whl:
Publisher:
publish.yml on alvaro-brito/python2mobile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python2mobile-0.1.7-py3-none-any.whl -
Subject digest:
f72569f7253dcfed847eb9491291cc551120abd00b19f2078a19452393479c00 - Sigstore transparency entry: 1108173824
- Sigstore integration time:
-
Permalink:
alvaro-brito/python2mobile@e7835abc0a269b0c5e1b1a8b21733fa51b2e4288 -
Branch / Tag:
refs/tags/v0.1.7-RELEASE - Owner: https://github.com/alvaro-brito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7835abc0a269b0c5e1b1a8b21733fa51b2e4288 -
Trigger Event:
push
-
Statement type: