gitmyhub

python-periphery

★ 100 updated 6y ago ⑂ fork

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.

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.