A statically compiled Python to Native Android platform
Project description
Laith
Python → Native Android Compiler Platform.
Why
I have been doing React Native for half a year and i wanted to dive into Android and RN internals. After diving i wondered why we don't have a similar project for Python. I coded this by not following existing projects approaches.
What Laith means
Laith (ليث) means lion and is the name of my cat. Could not find a better name.
Architecture
- Frontend: AST-based semantic analysis and type inference.
- IR: SSA-based Intermediate Representation.
- Optimizer: Multi-pass IR optimization (DCE, Constant Folding).
- Backend: Multi-layered emission (Kotlin/Compose + Native C++/JNI).
- Orchestrator: Automated Gradle/NDK build system and ADB device runner.
Usage
# Initialize a professional project
laith init myapp
# Compile the default entry point (src/main.py)
laith build
# Build the native Android APK
laith compile
# The "Inner Loop": Build, Install, Run, and Stream Logs
laith run
Project Configuration (laith.toml)
Laith uses a declarative, versioned manifest to manage the full Android lifecycle.
# laith.toml
version = "1.0"
[app]
name = "MyAwesomeApp"
namespace = "com.company.awesome"
identity = { id = "com.company.awesome", version_code = 42, version_name = "2.1.0" }
[sdk]
min = 26
target = 34
compile = 34
[dependencies]
implementation = [
"com.squareup.retrofit2:retrofit:2.9.0",
"androidx.compose.material3:material3:1.2.0"
]
[features]
compose = true
native = true
Ai Contribution Policy
This project uses AI. If you use Ai and bring sensible improvement, then great. If it's mindless slop, then it wont get reviewed.
Core Principles
- No embedded CPython: No interpreter overhead; small binaries and fast startup.
- Compiled, not interpreted: Statically analyzed and optimized for the Android runtime.
- Native Stack Alignment: Direct mapping to Compose, Coroutines, and WorkManager.
- Zero-JNI Performance: Automated C++ and JNI bridge generation for native code.
Supported Python Subset
Laith currently supports a statically-analyzed subset of Python 3.10+:
- Syntax:
def,async def,return, assignments, and hierarchical function calls. - Types:
int,str,bool, andvoid(explicit annotations or inferred). - Async/Await: Full mapping to Kotlin Coroutines for non-blocking I/O and UI.
- State Management:
state(initial_value)for reactive UI/background synchronization. - IPC:
Channel()for event-based communication between layers. - UI Components: Jetpack Compose DSL (
Column,Row,Box,Text,Button). - Native:
@nativedecorator for high-performance C++ implementation. - Background:
@periodic_task(WorkManager) and@foreground_service(Android Services).
Not Supported (Yet)
To maintain high performance and static predictability, the following Python features are not supported:
- Dynamic Execution:
eval(),exec(), and dynamic__import__(). - Runtime Metaprogramming: Metaclasses, monkey patching, and dynamic attribute injection.
- Reflection: Unrestricted
getattr/setattron arbitrary objects. - Classes & Inheritance: Custom class definitions are planned for Phase 6.
- Exception Handling:
try/exceptblocks are planned for Phase 7.
Complete Application Demo
from laith import Column, Text, Button, vibrate
def main_ui():
Column(
Text("Laith Vibe Lab"),
Text("Press buttons to test haptic feedback"),
Button("Quick Vibe (100ms)", on_click=lambda: vibrate(100)),
Button("Medium Vibe (500ms)", on_click=lambda: vibrate(500)),
Button("Long Vibe (1s)", on_click=lambda: vibrate(1000))
)
Why Laith? (Comparison)
Laith represents a fundamental shift in how Python is used for mobile development. Unlike existing tools that wrap an interpreter, Laith treats Python as a high-level frontend for a native compiler.
vs. Kivy & BeeWare
- No Interpreter: Kivy and BeeWare bundle a full CPython interpreter (libpython) inside your APK. Laith statically compiles Python into Kotlin/JVM and C++.
- Native UI: Laith generates real Jetpack Compose code, using the exact same primitives as modern Android apps, rather than OpenGL custom views.
vs. React Native
- No Runtime Bridge: React Native relies on a JavaScript bridge. Laith eliminates this overhead by compiling everything to native bytecode or JNI-linked C++ before the app even runs.
- Type Safety: Laith enforces a strictly typed subset, catching errors at compile-time that would be runtime crashes in JS.
vs. Flutter
- Ecosystem Alignment: Laith embraces the Android Native Stack, mapping Python directly to Kotlin Coroutines, WorkManager, and Jetpack Compose.
- Direct NDK Access: While Flutter requires complex MethodChannels, Laith allows you to mark Python functions with
@nativeto generate optimized C++ and automated JNI bridges instantly.
Project details
Release history Release notifications | RSS feed
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 laith-0.1.0.tar.gz.
File metadata
- Download URL: laith-0.1.0.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1de20acb52010c948b4b332a282880b8980beddb74fd52f1ae9c09cc29143d0d
|
|
| MD5 |
f0a315338600e40cae59cc1556489367
|
|
| BLAKE2b-256 |
47e103ffae01db557bd9ed0847a7d296277ab331e5700c9fd77b08204041a05e
|
File details
Details for the file laith-0.1.0-py3-none-any.whl.
File metadata
- Download URL: laith-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae99937d7ed750b0ad877cda6aece43c796bf0ba80acb3fec2de226c4259171b
|
|
| MD5 |
8b407e41ff1e2dc7b31796ed05f4e239
|
|
| BLAKE2b-256 |
30edf79499aaf6dfd8a7b9ac6fe6860f1eedd37e9760cc6468af0a42caa059ca
|