Skip to main content

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

  1. No embedded CPython: No interpreter overhead; small binaries and fast startup.
  2. Compiled, not interpreted: Statically analyzed and optimized for the Android runtime.
  3. Native Stack Alignment: Direct mapping to Compose, Coroutines, and WorkManager.
  4. 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, and void (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: @native decorator 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/setattr on arbitrary objects.
  • Classes & Inheritance: Custom class definitions are planned for Phase 6.
  • Exception Handling: try/except blocks 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 @native to generate optimized C++ and automated JNI bridges instantly.

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

laith-0.1.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

laith-0.1.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

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

Hashes for laith-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1de20acb52010c948b4b332a282880b8980beddb74fd52f1ae9c09cc29143d0d
MD5 f0a315338600e40cae59cc1556489367
BLAKE2b-256 47e103ffae01db557bd9ed0847a7d296277ab331e5700c9fd77b08204041a05e

See more details on using hashes here.

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

Hashes for laith-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae99937d7ed750b0ad877cda6aece43c796bf0ba80acb3fec2de226c4259171b
MD5 8b407e41ff1e2dc7b31796ed05f4e239
BLAKE2b-256 30edf79499aaf6dfd8a7b9ac6fe6860f1eedd37e9760cc6468af0a42caa059ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page