Skip to content

Write the app in Python. Install a native Android app.

ApkPy compiles your Python into Java, XML and a Gradle project. There is no Python on the phone, and the project opens in Android Studio.

pip install apkpy What is new in 1.14.1

Lumen, a personal finance app built with ApkPy, running on an Android phone
Lumen, built with ApkPy, running on a phone.

Python in, Android out

One file of Python is the whole app: its screens, its state and what each button does. ApkPy reads it and writes the Android project, the files you would otherwise write by hand.

writehere.py

from apkpy_lib import Screen, button, label, run

home = Screen(id="home")
count = label("0", id="count", screen=home)


def add():
    count.set_value(str(int(count.get_value()) + 1))


button("Add one", id="add", command=add, screen=home)
run(start_screen=home)

res/layout/activity_screen_home.xml, generated

<TextView
    android:id="@+id/lbl1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="0"
    android:textSize="16sp" />

<Button
    android:id="@+id/btn1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Add one" />

The rest of what that file becomes: AndroidManifest.xml, Screen_homeActivity.java with the button's listener, and the light and dark themes in res/values and res/values-night. How generation works

No Python on the phone

Your code becomes Java and XML. The APK carries no interpreter and no web page.

How it is translated
Opens in Android Studio

apkpy build gives you the Gradle project, to read, change and build like any other.

Build and release
1.48 MiB release

A 100-note app, signed and shrunk, installed and measured on Android.

The benchmark

Four apps built with it

Each one has four screens and working navigation, and each was installed on a phone with every tab opened. The pictures are those APKs.

The showcase, with the code of each app · Can ApkPy build your app?

Three commands

python writehere.py

The Previewer opens the app on your computer in seconds: screens, inputs, navigation and storage.

apkpy run

A debug APK, left in your folder. Add --usb to install it on a phone, or --qr to install it over Wi-Fi.

apkpy build

The whole Android project as a ZIP, ready for Android Studio.

Questions people ask first

Does the APK contain Python?

No. ApkPy compiles your Python into native Android Java, XML and resources. The app does not carry a Python interpreter.

Which Python can I write?

The Python you write apps with: functions, loops, lists and dicts, comprehensions, f-strings, try, and classes with @dataclass. In place of pip packages, ApkPy brings its own APIs for HTTP, data, files, background work and the device. The full list · The API reference

Can I open the result in Android Studio?

Yes. apkpy build produces a Gradle project ZIP for inspection, emulator testing and the usual Android tools.

Is the Previewer enough to test?

Use it for fast feedback, then check permissions, services and the final look on an emulator or a phone. How the two compare

Start with a small screen, then open what it generated.

Install ApkPy

Open source

ApkPy is open source under the Apache License 2.0, and the apps you build with it are yours: an exception in the licence leaves them free of its conditions. Read what the licence says.