Convert Figma logo to code with AI

kivy logoplyer

Plyer is a platform-independent Python wrapper for platform-dependent APIs

1,636
427
1,636
183

Top Related Projects

2,265

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

4,407

A Python native, OS native GUI toolkit.

11,752

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

1,100

Redis for humans. 🌎🌍🌏

Quick Overview

Plyer is a platform-independent way of accessing native features of the device. It provides a unified API to access features like GPS, accelerometer, camera, and more, across multiple platforms including Android, iOS, Linux, and Windows.

Pros

  • Cross-platform Compatibility: Plyer allows developers to write code that can run on multiple platforms without having to deal with platform-specific APIs.
  • Unified API: Plyer provides a consistent API for accessing native device features, making it easier to write cross-platform code.
  • Active Development: The project is actively maintained and has a growing community of contributors.
  • Extensive Feature Set: Plyer supports a wide range of native device features, including GPS, accelerometer, camera, and more.

Cons

  • Limited Documentation: The project's documentation could be more comprehensive, which may make it challenging for new users to get started.
  • Dependency on Kivy: Plyer is primarily designed to work with the Kivy framework, which may limit its usefulness for developers who are not using Kivy.
  • Potential Performance Issues: Depending on the native feature being accessed, there may be some performance overhead associated with using Plyer.
  • Limited Platform Support: While Plyer supports multiple platforms, it may not have complete parity across all platforms, and some features may not be available on certain platforms.

Code Examples

Here are a few examples of how to use Plyer:

  1. Accessing the GPS:
from plyer import gps

gps.configure(on_location=on_gps_location,
              on_status=on_gps_status)
gps.start()

def on_gps_location(lat, lon):
    print(f'GPS location: {lat}, {lon}')

def on_gps_status(status_message, is_active):
    print(f'GPS status: {status_message}, is_active: {is_active}')
  1. Taking a Photo:
from plyer import camera

def take_photo():
    camera.take_picture(filename='photo.png', on_complete=photo_taken)

def photo_taken(filename):
    print(f'Photo saved to: {filename}')

take_photo()
  1. Accessing the Accelerometer:
from plyer import accelerometer

accelerometer.enable()

def on_accelerometer_event(acceleration):
    print(f'Acceleration: {acceleration}')

accelerometer.subscribe(on_accelerometer_event)
  1. Displaying a Notification:
from plyer import notification

notification.notify(
    title='Hello',
    message='This is a notification',
    timeout=10
)

Getting Started

To get started with Plyer, you'll need to have Kivy installed. You can install Kivy using pip:

pip install kivy

Once you have Kivy installed, you can install Plyer using pip:

pip install plyer

After installing Plyer, you can start using it in your Kivy application. Here's a simple example that demonstrates how to access the device's GPS:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from plyer import gps

class GPSApp(App):
    def build(self):
        layout = BoxLayout(orientation='vertical')

        self.label = Label(text='Waiting for GPS signal...')
        layout.add_widget(self.label)

        gps.configure(on_location=self.update_label,
                      on_status=self.on_gps_status)
        gps.start()

        return layout

    def update_label(self, lat, lon):
        self.label.text = f'GPS location: {lat}, {lon}'

    def on_gps_status(self, stype, status):
        self.label.text = 'GPS status: {}, {}'.format(stype, status)

if __name__ == '__main__':
    GPSApp().run()

This example sets up a simple Kivy application that displays the device's GPS coordinates. The gps.configure()

Competitor Comparisons

2,265

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd

Pros of KivyMD

  • Provides a comprehensive set of Material Design widgets for Kivy
  • Offers a more modern and polished UI appearance out-of-the-box
  • Actively maintained with frequent updates and new features

Cons of KivyMD

  • Larger library size and potentially higher resource usage
  • Steeper learning curve for developers new to Material Design concepts
  • May require more setup and configuration compared to Plyer

Code Comparison

KivyMD example:

from kivymd.app import MDApp
from kivymd.uix.button import MDRaisedButton

class MyApp(MDApp):
    def build(self):
        return MDRaisedButton(text="Hello, World!")

Plyer example:

from kivy.app import App
from kivy.uix.button import Button
from plyer import notification

class MyApp(App):
    def build(self):
        return Button(text="Hello, World!", on_press=self.notify)
    
    def notify(self, instance):
        notification.notify(title="Hello", message="World!")

KivyMD focuses on providing Material Design widgets, while Plyer offers platform-specific features like notifications. KivyMD is better suited for creating visually appealing UIs, whereas Plyer is more useful for accessing device capabilities across different platforms.

17,941

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS

Pros of Kivy

  • Comprehensive framework for developing cross-platform applications
  • Extensive documentation and large community support
  • Rich set of UI elements and widgets

Cons of Kivy

  • Steeper learning curve due to its extensive feature set
  • Larger file size and resource consumption

Code Comparison

Kivy:

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        return Button(text='Hello World')

MyApp().run()

Plyer:

from plyer import notification

notification.notify(
    title='Hello',
    message='World',
    app_icon=None,
    timeout=10
)

Summary

Kivy is a comprehensive framework for building cross-platform applications with a focus on UI development. It offers a wide range of features and widgets but may require more learning and resources. Plyer, on the other hand, is a simpler library that provides a unified interface to access various platform-dependent features like notifications, GPS, and accelerometer. While Kivy is better suited for full-fledged application development, Plyer is ideal for accessing specific device functionalities across different platforms with minimal code.

4,407

A Python native, OS native GUI toolkit.

Pros of Toga

  • Native look and feel across platforms
  • Broader range of supported widgets and UI elements
  • More comprehensive documentation and examples

Cons of Toga

  • Steeper learning curve for beginners
  • Less mature and stable compared to Plyer
  • Smaller community and fewer third-party extensions

Code Comparison

Toga example:

import toga

def button_handler(widget):
    print("Hello, World!")

def build(app):
    box = toga.Box()
    button = toga.Button('Hello World', on_press=button_handler)
    box.add(button)
    return box

def main():
    return toga.App('First App', 'org.example.first', startup=build)

if __name__ == '__main__':
    main().main_loop()

Plyer example:

from kivy.app import App
from kivy.uix.button import Button
from plyer import notification

class MyApp(App):
    def build(self):
        return Button(text='Hello World', on_press=self.notify)

    def notify(self, instance):
        notification.notify(title='Hello', message='World!')

if __name__ == '__main__':
    MyApp().run()

Both Toga and Plyer aim to provide cross-platform functionality for Python applications, but they differ in their approach and focus. Toga offers a more comprehensive UI toolkit with native widgets, while Plyer concentrates on providing a unified interface for platform-specific features like notifications and GPS.

11,752

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

Pros of Flet

  • Focuses on building Flutter-based UIs for multiple platforms
  • Offers a more modern and visually appealing UI framework
  • Provides a simpler API for creating responsive layouts

Cons of Flet

  • Less mature and has a smaller community compared to Plyer
  • Limited to Flutter-based development, while Plyer is more flexible
  • May have a steeper learning curve for developers new to Flutter

Code Comparison

Flet example:

import flet as ft

def main(page: ft.Page):
    page.add(ft.Text("Hello, World!"))

ft.app(target=main)

Plyer example:

from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):
    def build(self):
        return Label(text='Hello, World!')

MyApp().run()

Both examples create a simple "Hello, World!" application, but Flet uses a more modern, Flutter-inspired approach, while Plyer relies on Kivy's traditional structure.

1,100

Redis for humans. 🌎🌍🌏

Pros of Pottery

  • Pottery provides a more modern and streamlined API compared to Plyer, with a focus on simplicity and ease of use.
  • Pottery has a more active development community, with regular updates and improvements.
  • Pottery's documentation is generally more comprehensive and user-friendly.

Cons of Pottery

  • Pottery has a smaller ecosystem and fewer supported features compared to Plyer, which has a larger and more established user base.
  • Pottery may have less compatibility with older or less common platforms, as it is a newer project.
  • Pottery's performance and stability may not be as thoroughly tested as Plyer's, which has been around for longer.

Code Comparison

Plyer:

from plyer import accelerometer

accelerometer.start()
x, y, z = accelerometer.acceleration
accelerometer.stop()

Pottery:

from pottery.sensors import accelerometer

accelerometer.start()
x, y, z = accelerometer.read()
accelerometer.stop()

The main difference in the code is the way the accelerometer is accessed and used. Pottery provides a more concise and intuitive API, while Plyer has a slightly more verbose approach.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Plyer

Plyer is a platform-independent Python API for accessing hardware features of various platforms (Android, iOS, macOS, Linux and Windows).

Plyer is managed by the Kivy Team. It is suitable for use with Kivy apps, but can be used independently.

Backers on Open Collective Sponsors on Open Collective GitHub contributors Contributor Covenant

PyPI - Version PyPI - Python Version

coverage Continuous Integration with Ubuntu Continuous Integration with OSX Continuous Integration with Windows Deploy to PyPI

How plyer works?

Plyer tries not to reinvent the wheel, and will call external libraries to implement the API in the easiest way, depending on the current platform.

Supported APIs

PlatformAndroidiOSWindowsmacOSLinux
Accelerometer✔✔✔✔
Audio recording✔✔✔
Barometer✔✔
Battery✔✔✔✔✔
Bluetooth✔✔
Brightness✔✔✔
Call✔✔
Camera (taking picture)✔✔
Compass✔✔
CPU count✔✔✔
Devicename✔✔✔✔
Email (open mail client)✔✔✔✔✔
Flash✔✔
GPS✔✔
Gravity✔✔
Gyroscope✔✔
Humidity✔
IR Blaster✔
Keystore✔✔✔✔✔
Light✔
Maps✔✔
Native file chooser✔✔✔✔✔
Notifications✔✔✔✔
Orientation✔✔
Proximity✔
Screenshot✔✔✔
SMS (send messages)✔✔✔
Spatial Orientation✔✔
Speech to text✔
Storage Path✔✔✔✔✔
Temperature✔
Text to speech✔✔✔✔✔
Unique ID✔✔✔✔✔
Vibrator✔✔
Wifi✔✔✔

Documentation

Full documentation, including details about the API, is available online. If you are not using the latest version of Plyer, earlier versions of the documentations are linked from there.

Installation

To use on desktop: pip install plyer To use in python-for-android and Kivy for iOS, add plyer to your requirements if needed.

License

Plyer is MIT licensed, actively developed by a great community and is supported by many projects managed by the Kivy Organization.

Support

Are you having trouble using Plyer or any of its related projects in the Kivy ecosystem? Is there an error you don’t understand? Are you trying to figure out how to use it? We have volunteers who can help!

The best channels to contact us for support are listed in the latest Contact Us document.

Contributing

Plyer is part of the Kivy ecosystem - a large group of products used by many thousands of developers for free, but it is built entirely by the contributions of volunteers. We welcome (and rely on) users who want to give back to the community by contributing to the project.

Contributions can come in many forms. See the latest Contribution Guidelines for how you can help us.

Code of Conduct

In the interest of fostering an open and welcoming community, we as contributors and maintainers need to ensure participation in our project and our sister projects is a harassment-free and positive experience for everyone. It is vital that all interaction is conducted in a manner conveying respect, open-mindedness and gratitude.

Please consult the latest Code of Conduct.

Contributors

This project exists thanks to all the people who contribute. [Become a contributor].

Backers

Thank you to all of our backers! 🙏 [Become a backer]

Sponsors

Special thanks to all of our sponsors, past and present. Support this project by [becoming a sponsor].

Here are our top current sponsors. Please click through to see their websites, and support them as they support us.