Registry / serialization / spidev

spidev

JSON →
library3.8pypypi✓ verified 85d ago

Python bindings for Linux SPI access through spidev. Current version 3.8 provides low-level control of SPI devices via the Linux spidev kernel interface. Release cadence is infrequent; maintained on GitHub.

pip install spidev
INSTALL
IMPORT
SIG · SPIDEV
S
spidev
serializationpythonv3.8
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
build_error
Code
Verified usage

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

SpiDev
from spidev import SpiDev
import spidev
Common mistake: 'import spidev' only gives access to the module object, not the SpiDev class. Use 'from spidev import SpiDev' for direct access.

Open SPI bus 0, device 0, transfer bytes, and close.

from spidev import SpiDev spi = SpiDev() spi.open(0, 0) # bus=0, device=0 spi.max_speed_hz = 1000000 spi.mode = 0b00 to_send = [0x01, 0x02, 0x03] response = spi.xfer(to_send) print(response) spi.close()
Debug
Known issues
gotchaBits per word default is 8. Changing to other values (e.g., 16) may cause unexpected transfer behavior unless hardware supports it.
fix
Set 'spi.bits_per_word = 8' explicitly, or check device datasheet before changing.
affects: all
breakingIn v3.8, the 'open_path' method was added. Older code using only 'open(bus, device)' still works, but dynamic bus allocation may require file path-based opening.
fix
Use 'spi.open_path("/dev/spidev0.0")' for dynamic bus numbering, or stick with 'spi.open(bus, device)' for static.
affects: >=3.8
deprecatedUsing 'spi.xfer2' is deprecated in favor of 'spi.xfer'. xfer2 was a non-standard name and may be removed in future versions.
fix
Replace 'spi.xfer2' with 'spi.xfer'.
affects: all
gotchaRunning without root or proper permissions (e.g., no udev rule) yields 'PermissionError' or 'OSError: [Errno 13] Permission denied'.
fix
Run as root, or add a udev rule to set permissions on /dev/spidev* (e.g., 'SUBSYSTEM=="spidev", MODE="0666"').
affects: all
Errors
Common errors & fixes
OSError: [Errno 2] No such file or directory
SPI device node does not exist; kernel module not loaded or incorrect bus/device number.
fix
Load the spidev module: 'sudo modprobe spidev' and check /dev for spidev files (e.g., ls /dev/spi*).
PermissionError: [Errno 13] Permission denied
User lacks read/write access to /dev/spidev*.
fix
Run as root or add a udev rule to grant permissions (e.g., 'SUBSYSTEM=="spidev", MODE="0666"').
AttributeError: module 'spidev' has no attribute 'SpiDev'
Incorrect import: using 'import spidev' instead of 'from spidev import SpiDev'.
fix
Use 'from spidev import SpiDev' to import the class.
TypeError: function takes at most 2 arguments (3 given)
Wrong number of arguments when calling 'open_path' — expects a single path string.
fix
Use 'spi.open_path("/dev/spidev0.0")' instead of 'spi.open_path(bus, device)'.
Upgrade
Version history
3.8latest on PyPI · released Sep 15, 2025
Audit
Dependencies
spidevrequiredSystem-level dependency: Linux spidev kernel module must be loaded (e.g., 'modprobe spidev')
Agent activity
2 hits · last 30 days
node
2
Resources
spidev — pip install spidev · libregistry