Skip to main content

A comprehensive Python library for creating Android applications with GUI support

Project description

PyAndroid - Python Library for Android Development

PyPI version Python Versions License Tests GitHub Stars

A comprehensive Python library for Android application development with real GUI support. PyAndroid provides a Pythonic interface for building Android applications using familiar Python patterns, with cross-platform deployment capabilities.

โœจ Key Features

  • ๐Ÿ“ฑ True Android Development: Build real Android apps with Python
  • ๐Ÿ’ป GUI Support: Actual graphical interfaces powered by Kivy
  • ๐ŸŽฏ Pythonic API: Familiar Python syntax and patterns
  • ๐Ÿš€ Cross-Platform: Deploy to Desktop, Android, and iOS
  • ๐Ÿงฉ Component-Based: Activities, Intents, Views, and Layouts
  • ๐Ÿ“ฆ Battery Included: File management, networking, logging utilities
  • ๐Ÿ”ง Extensible: Easy to extend with custom components
  • โœ… Well-Tested: Comprehensive test coverage
  • ๐Ÿ“š Documented: Full API documentation and examples

๐Ÿ“ฅ Installation

Quick Install

pip install pyandroid

With GUI Support (Recommended)

# Install with Kivy for GUI rendering
pip install "pyandroid[gui]"

Development Installation

# Install with all development tools
pip install "pyandroid[dev,gui]"

# Or install from source
git clone https://github.com/subhobhai943/pyandroid-dev.git
cd pyandroid-dev
pip install -e ".[gui]"

๐Ÿš€ Quick Start

Your First PyAndroid App

from pyandroid import AndroidApp, Activity
from pyandroid.ui import LinearLayout, Button, TextView

class MainActivity(Activity):
    def __init__(self):
        super().__init__("MainActivity")
        self.counter = 0
        
    def on_start(self):
        # Create main layout
        layout = LinearLayout("main_layout", orientation="vertical")
        
        # Add title
        title = TextView("title", "PyAndroid Counter App")
        title.set_text_size(24)
        title.set_text_color("#2196F3")
        layout.add_view(title)
        
        # Add counter display
        self.counter_text = TextView("counter", "Count: 0")
        self.counter_text.set_text_size(32)
        layout.add_view(self.counter_text)
        
        # Add increment button
        button = Button("btn_increment", "Increment")
        button.set_background_color("#4CAF50")
        button.set_on_click_listener(self.increment_counter)
        layout.add_view(button)
        
        # Set layout
        self.add_view("main_layout", layout)
    
    def increment_counter(self, view):
        self.counter += 1
        self.counter_text.set_text(f"Count: {self.counter}")

# Create and run app
app = AndroidApp("Counter App", "com.example.counter")
app.register_activity("main", MainActivity)
app.start_activity("main")
app.run()

Run this code and a real window opens with a working GUI! ๐ŸŽ‰

๐Ÿ“š Documentation

Core Components

AndroidApp - Main Application

from pyandroid import AndroidApp

# Create app with GUI support (default)
app = AndroidApp("MyApp", "com.example.myapp")

# Create app without GUI (console mode)
app = AndroidApp("MyApp", "com.example.myapp", use_gui=False)

# Register activities
app.register_activity("main", MainActivity)
app.register_activity("settings", SettingsActivity)

# Start activity
app.start_activity("main")

# Run the app
app.run()

Activity - Application Screens

from pyandroid import Activity
from pyandroid.ui import LinearLayout, TextView

class MyActivity(Activity):
    def __init__(self):
        super().__init__("MyActivity")
    
    def on_start(self):
        """Called when activity starts"""
        # Setup UI here
        pass
    
    def on_resume(self):
        """Called when activity resumes"""
        pass
    
    def on_pause(self):
        """Called when activity pauses"""
        pass

UI Components

TextView - Display Text

from pyandroid.ui import TextView

title = TextView("title", "Welcome!")
title.set_text_color("#FF5722")
title.set_text_size(28)
title.set_background_color("#FFFFFF")

Button - Interactive Element

from pyandroid.ui import Button

def on_click(view):
    print("Button clicked!")

button = Button("my_button", "Click Me")
button.set_background_color("#2196F3")
button.set_text_color("#FFFFFF")
button.set_on_click_listener(on_click)

EditText - User Input

from pyandroid.ui import EditText

input_field = EditText("user_input", hint="Enter your name")
input_field.set_text("John")
text = input_field.get_text()

Layouts - Organize Views

from pyandroid.ui import LinearLayout, TextView, Button

# Vertical layout
layout = LinearLayout("main", orientation="vertical")

# Add children
layout.add_view(TextView("tv1", "Title"))
layout.add_view(Button("btn1", "Action"))

# Horizontal layout
row = LinearLayout("row", orientation="horizontal")
row.add_view(Button("btn2", "Left"))
row.add_view(Button("btn3", "Right"))

layout.add_view(row)

Utilities

File Management

from pyandroid.utils import FileManager

fm = FileManager("MyApp")

# JSON files
data = {"user": "Alice", "score": 95}
fm.save_json("data.json", data)
loaded = fm.load_json("data.json")

# Text files
fm.write_file("notes.txt", "My notes")
content = fm.read_file("notes.txt")

# List files
files = fm.list_files()

Networking

from pyandroid.utils import NetworkManager

net = NetworkManager("MyApp")

# Check connection
if net.is_connected():
    # GET request
    response = net.get("https://api.example.com/data")
    
    # POST with JSON
    data = {"name": "Bob", "age": 25}
    result = net.post_json("https://api.example.com/users", data)

Logging

from pyandroid.utils import Logger

logger = Logger("MyApp")

logger.debug("Debug information")
logger.info("App started")
logger.warning("Low battery")
logger.error("Connection failed")

๐Ÿ“ฑ Building APK for Android

Convert your Python app to an Android APK:

Using Buildozer (Recommended)

# Install Buildozer
pip install buildozer

# Initialize
buildozer init

# Edit buildozer.spec
# requirements = python3,kivy,pyandroid

# Build APK (first time: 20-60 minutes)
buildozer -v android debug

# Deploy to connected device
buildozer android debug deploy run

Using python-for-android

pip install python-for-android

p4a apk --private . \
    --package=com.example.myapp \
    --name "My App" \
    --version 0.1 \
    --bootstrap=sdl2 \
    --requirements=python3,kivy,pyandroid \
    --permission INTERNET

๐Ÿงช Examples

Calculator App

A full calculator with GUI: pyandroid-calculator-app

Todo List App

from pyandroid import AndroidApp, Activity
from pyandroid.ui import LinearLayout, Button, EditText, TextView

class TodoActivity(Activity):
    def __init__(self):
        super().__init__("TodoActivity")
        self.todos = []
    
    def on_start(self):
        layout = LinearLayout("main", orientation="vertical")
        
        # Input area
        self.input_field = EditText("todo_input", hint="Enter task")
        layout.add_view(self.input_field)
        
        # Add button
        add_btn = Button("add_btn", "Add Task")
        add_btn.set_on_click_listener(self.add_todo)
        layout.add_view(add_btn)
        
        # Todo list display
        self.todo_display = TextView("todos", "No tasks yet")
        layout.add_view(self.todo_display)
        
        self.add_view("main", layout)
    
    def add_todo(self, view):
        task = self.input_field.get_text()
        if task:
            self.todos.append(task)
            self.input_field.set_text("")
            self.update_display()
    
    def update_display(self):
        text = "\n".join(f"{i+1}. {todo}" for i, todo in enumerate(self.todos))
        self.todo_display.set_text(text or "No tasks yet")

app = AndroidApp("Todo List", "com.example.todo")
app.register_activity("main", TodoActivity)
app.start_activity("main")
app.run()

๐Ÿงฐ Testing

PyAndroid includes a comprehensive test suite:

# Run all tests
pytest tests/

# Run with coverage
pytest --cov=pyandroid tests/

# Run specific test file
pytest tests/test_core.py

๐Ÿ“ License

This project is licensed under the PyAndroid Custom License v1.0.

Key Points:

  • โœ… Free for personal and educational use
  • โœ… Open source requirement for derivative works
  • โœ… Attribution required
  • โŒ Commercial use requires permission

See LICENSE file for complete terms.

For commercial licensing: contact the maintainer

๐Ÿ›ฃ๏ธ Roadmap

v1.3 (Planned)

  • WebView component
  • SQLite database integration
  • Enhanced animation support
  • More layout types

v1.4 (Future)

  • Push notifications
  • Camera and media access
  • Sensor integration
  • Background services
  • Material Design components

v2.0 (Vision)

  • Hot reload support
  • Visual UI builder
  • Plugin system
  • Cloud backend integration

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

๐Ÿ“Š Stats

  • ๐Ÿ‘จโ€๐Ÿ’ป Actively Maintained: Regular updates and improvements
  • ๐Ÿ“š Well Documented: Comprehensive guides and API docs
  • โœ… Tested: High test coverage
  • ๐Ÿ”’ Stable API: Semantic versioning
  • ๐Ÿ‘ฅ Community: Growing community of developers

โ“ FAQ

Q: Can I build real Android apps with this?
A: Yes! PyAndroid uses Kivy as a backend which can compile to native Android APKs.

Q: Do I need to know Java?
A: No! Write everything in Python.

Q: Is it production-ready?
A: PyAndroid is in beta. It's suitable for learning, prototyping, and small projects.

Q: Can I publish to Google Play?
A: Yes! Apps built with PyAndroid can be published to app stores.

Q: What's the performance like?
A: Good for most use cases. Performance-critical sections can use Cython.

๐Ÿ“ž Support

๐Ÿ“š Resources

๐ŸŒŸ Star History

If you find PyAndroid useful, please star the repository! โญ

๐Ÿš€ Built With PyAndroid

Showcase your app! Open an issue to add your project here.

๐Ÿ“ Changelog

v1.2.0 (2025-11-09)

  • โœจ Added comprehensive test suite
  • ๐Ÿ“ฆ Prepared for PyPI deployment
  • ๐Ÿ“ Added custom license
  • ๐Ÿš€ Added GitHub Actions CI/CD
  • ๐Ÿ“– Enhanced documentation
  • ๐Ÿ› Bug fixes and improvements

v1.1.0 (2025-11-09)

  • โœจ Added Kivy backend for GUI rendering
  • ๐Ÿ“ฑ Real graphical interface support
  • ๐Ÿš€ Cross-platform desktop and Android support
  • ๐Ÿ“– Updated documentation

v1.0.0 (2024-10-24)

  • ๐ŸŽ‰ Initial release
  • ๐Ÿ“ฆ Core Android components (App, Activity, Intent)
  • ๐ŸŽจ Complete UI framework (Views, Layouts, Widgets)
  • ๐Ÿ› ๏ธ Utility classes (Logger, FileManager, NetworkManager)

Made with โค๏ธ by Subhobhai

โญ Star ยท ๐Ÿ› Report Bug ยท โœจ Request Feature

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

pyandroid_dev-1.2.1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

pyandroid_dev-1.2.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file pyandroid_dev-1.2.1.tar.gz.

File metadata

  • Download URL: pyandroid_dev-1.2.1.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyandroid_dev-1.2.1.tar.gz
Algorithm Hash digest
SHA256 3db70f8170fb5ff061c409ce8e4c7ca5825100a5a18bf5d4d1d9f927a4b8d087
MD5 9d54fc25b0d59142c12216d91ac644fe
BLAKE2b-256 79fc171d1faf074278c47e3e3eb85cac1cbf5863bee30d0d0a6f9bef4a4f47db

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyandroid_dev-1.2.1.tar.gz:

Publisher: publish-to-pypi.yml on subhobhai943/pyandroid-dev

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyandroid_dev-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: pyandroid_dev-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyandroid_dev-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9098914f321ede0c6af99fba9abed737b823a70b43c5a206edc1a3c88d2c1d
MD5 9bbcbbc552cf4c29ecdaa4db66b7ed35
BLAKE2b-256 44fd8718d2c1fd17abf978424609740b26bf94a1107ac1366abafcc545cb528c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyandroid_dev-1.2.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on subhobhai943/pyandroid-dev

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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