Plyer

2.1.0 · active · verified Thu Apr 16

Plyer is a platform-independent Python API that provides a unified interface for accessing hardware features and platform-dependent functionalities across various operating systems, including Android, iOS, macOS, Linux, and Windows. It is actively managed by the Kivy Team and, while suitable for Kivy applications, can be used independently. The library wraps existing platform-specific APIs and often leverages external tools like PyJNIus for Android and PyObjus for iOS/macOS to achieve its cross-platform compatibility. The current version is 2.1.0, with ongoing development and maintenance by the Kivy community.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to send a simple desktop notification using Plyer. The `notification.notify()` method is cross-platform, though specific parameters like `app_icon` may have platform-dependent requirements (e.g., `.ico` format on Windows). It also includes commented-out conceptual code for a mobile-focused feature like battery status, highlighting Plyer's broader capabilities beyond desktop.

from plyer import notification
import time

if __name__ == '__main__':
    print("Sending desktop notification...")
    try:
        notification.notify(
            title='Hello from Plyer!',
            message='This is a cross-platform notification example.',
            app_name='Plyer Quickstart',
            # app_icon='path/to/icon.ico', # On Windows, must be .ico format
            timeout=5  # Notification will disappear after 5 seconds
        )
        print("Notification sent. Check your system tray.")
    except Exception as e:
        print(f"Failed to send notification: {e}")
        print("Ensure your system supports desktop notifications and any backend dependencies are met.")

    # Example for a mobile-focused feature (conceptual, won't run on desktop without backend)
    # from plyer import battery
    # try:
    #     info = battery.status
    #     print(f"Battery Status: {info['percent']}% {'(charging)' if info['isCharging'] else ''}")
    # except Exception as e:
    #     print(f"Could not get battery info: {e}")

view raw JSON →