Registry / devops / lgpio
library0.2.2.0pypypi✓ verified 84d ago

A Python library for controlling GPIO on Linux single-board computers (SBCs) such as Raspberry Pi, Orange Pi, etc. Current version 0.2.2.0. Release cadence is irregular, primarily maintained by joan2937.

pip install lgpio
INSTALL
IMPORT
SIG · LGPIO
L
lgpio
devopspythonv0.2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lgpio
import lgpio
import RPi.GPIO
lgpio replaces RPi.GPIO on newer Linux kernels, but its API is different.
gpiochip_open
h = lgpio.gpiochip_open(0)
h = lgpio.gpio_open(0)
Use gpiochip_open, not gpio_open (which doesn't exist).

Open GPIO chip 0, claim GPIO 17 as output, set high, then cleanup.

import lgpio import os chip = int(os.environ.get('GPIO_CHIP', '0')) handle = lgpio.gpiochip_open(chip) # Set up output on GPIO 17 lgpio.gpio_claim_output(handle, 17) lgpio.gpio_write(handle, 17, 1) lgpio.gpio_free(handle, 17) lgpio.gpiochip_close(handle)
Debug
Known issues
breakingThe API is completely different from RPi.GPIO. Functions are prefixed with 'gpio' and require a handle from gpiochip_open. Do not use pin numbers as in RPi.GPIO; use GPIO numbers (BCM) or line offsets.
fix
Learn the new API: use lgpio.gpiochip_open, gpio_claim_output, gpio_write, etc.
affects: 0.x
gotchalgpio works on a per-chip basis. The chip number may vary between SBCs (typically 0 for Raspberry Pi 3/4, 1 for Pi 5).
fix
Use /dev/gpiochip* to discover correct chip number, or use lgpio.gpiochip_open_by_label() with the appropriate label.
affects: All
gotchagpio_free() must be called before gpiochip_close() to release claimed lines; otherwise, subsequent opens may fail.
fix
Always call gpio_free() for each claimed line, then gpiochip_close().
affects: All
Errors
Common errors & fixes
PermissionError: [Errno 13] Permission denied: '/dev/gpiochip0'
User does not have read/write access to /dev/gpiochip devices.
fix
Add user to the 'gpio' group: sudo usermod -a -G gpio $USER (then log out/in). Alternatively, run as root.
user-gpio library not found or import lgpio fails
The C library liblgpio.so is not installed or not found in library path.
fix
Install lgpio from pip; if on a SBC, ensure you have the proper liblgpio-dev or build from source. On Raspberry Pi OS, install with apt-get install liblgpio-dev.
AttributeError: module 'lgpio' has no attribute 'setwarnings'
Trying to use RPi.GPIO function setwarnings() on lgpio.
fix
lgpio does not use setwarnings. Remove that call.
Upgrade
Version history
0.2.2.0latest on PyPI · released Mar 29, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
lgpio — pip install lgpio · libregistry