Kivy — Open-Source Python Framework for Cross-Platform Apps with a Single Codebase
Kivy lets you write touch-friendly cross-platform apps entirely in Python. One codebase runs on iOS, Android, Windows, macOS, Linux, and Raspberry Pi — the Python way to build mobile and kiosk UIs.
What it is
Kivy is an open-source Python framework for building cross-platform applications with touch-friendly UIs. A single Python codebase runs on iOS, Android, Windows, macOS, Linux, and Raspberry Pi. Kivy uses its own rendering engine (OpenGL-based) rather than native platform widgets.
Kivy is for Python developers who want to build mobile or kiosk applications without learning Swift, Kotlin, or platform-specific UI toolkits. It is particularly suited for interactive applications, data visualization tools, and educational software.
How it saves time or tokens
Without Kivy, building a cross-platform app in Python requires separate codebases for each platform or wrapping Python in a native shell. Kivy provides a single framework that handles input, rendering, and packaging across all targets.
Kivy's declarative KV language separates UI layout from Python logic, making it easy to iterate on interfaces without changing business code. You define widgets, layouts, and bindings in .kv files and keep your Python files focused on logic.
How to use
- Install Kivy:
pip install kivy
- Create a basic application:
# main.py
from kivy.app import App
from kivy.uix.button import Button
class HelloApp(App):
def build(self):
return Button(text='Hello, Kivy!', font_size=40)
if __name__ == '__main__':
HelloApp().run()
- Run the app on desktop:
python main.py
- For mobile deployment, use Buildozer (Android) or kivy-ios:
pip install buildozer
buildozer init
buildozer android debug deploy
Example
A calculator layout using KV language:
# main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class CalcLayout(BoxLayout):
def calculate(self, expression):
try:
self.ids.result.text = str(eval(expression))
except Exception:
self.ids.result.text = 'Error'
class CalcApp(App):
def build(self):
return CalcLayout()
if __name__ == '__main__':
CalcApp().run()
# calc.kv
<CalcLayout>:
orientation: 'vertical'
TextInput:
id: expression
font_size: 32
multiline: False
Label:
id: result
font_size: 32
Button:
text: '='
on_press: root.calculate(expression.text)
Related on TokRepo
- Coding AI tools -- developer tools and frameworks
- Design AI tools -- UI design and prototyping tools
Common pitfalls
- Kivy does not use native platform widgets. Your app will not look like a native iOS or Android app out of the box. For native look-and-feel, consider KivyMD (Material Design components for Kivy).
- Android packaging with Buildozer requires specific system dependencies (Java JDK, Android SDK, NDK). The initial setup on Linux or macOS takes effort. Buildozer handles downloads but environment issues are common.
- Kivy's OpenGL rendering means it does not support all accessibility features that native frameworks provide. Screen readers and platform accessibility APIs have limited integration.
Frequently Asked Questions
Yes. Kivy apps can be packaged for iOS using kivy-ios and for Android using Buildozer or python-for-android. Apps built with Kivy have been published to both stores, though they require the same review process as any other app.
Flutter uses Dart and renders with Skia, producing near-native performance and look. Kivy uses Python and OpenGL. Flutter has a larger ecosystem and more polished widgets. Kivy's advantage is that you stay in Python and can leverage the entire Python ecosystem for backend logic, data science, and ML.
Yes. Kivy was designed for multi-touch from the beginning. It supports gestures, pinch-to-zoom, rotation, and multi-finger input on all platforms that provide touch events.
KV is Kivy's declarative language for defining UI layouts. It separates widget hierarchy and styling from Python logic, similar to how QML works with Qt. KV files use indentation-based syntax and support property binding and event callbacks.
Yes. Since Kivy runs on Python, you can use NumPy, TensorFlow, PyTorch, and other ML libraries alongside your Kivy app. This makes Kivy suitable for building interactive ML demos, data visualization tools, and inference UIs.
Citations (3)
- Kivy GitHub— Kivy cross-platform Python framework
- Kivy Documentation— KV language and widget documentation
- Buildozer GitHub— Buildozer for Android packaging
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.