python-periphery
A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
A pure-Python library for controlling hardware on Linux boards like Raspberry Pi, GPIO, PWM, SPI, I2C, serial, and more, without writing low-level code.
python-periphery Explanation
python-periphery is a Python library that lets you control hardware devices connected to a Linux computer—like sensors, motors, lights, and switches. If you're building an embedded project on a Raspberry Pi, BeagleBone, or similar device, this library gives you a straightforward way to read inputs and control outputs without needing to write low-level code.
The library supports seven types of hardware connections: GPIO (digital pins you can read or write to), LEDs (you can turn on/off or dim), PWM (a way to control motor speed or brightness precisely), SPI and I2C (standard communication protocols for talking to sensors and chips), MMIO (direct memory access for advanced use), and Serial (USB or RS-232 connections). You simply import the tool you need, open a connection to your device, and call methods to read or write values. The library handles all the Linux-level mechanics behind the scenes, so you don't have to. It works with both Python 2 and Python 3 and is written in pure Python, meaning no compilation or special dependencies are required.
A typical use case: you're building a home automation system and want to read a temperature sensor, turn on a fan motor, and flash an LED. Instead of wrestling with kernel drivers or low-level system calls, you'd write a few lines of Python that clearly express what you want to happen. The library abstracts away the complexity of talking directly to the operating system.
The project includes documentation and examples for each interface type, so you can quickly see how to do whatever you need. It's MIT licensed, meaning you can use it freely in personal or commercial projects.
Where it fits
- Read a temperature sensor and control a fan motor from a Raspberry Pi or BeagleBone using plain Python
- Flash an LED or dim it with PWM without writing kernel drivers
- Talk to sensors and chips over SPI or I2C for an embedded project
- Control GPIO pins directly for a home automation or robotics prototype