Skip to main content

Python bindings for Linux SPI access through spidev

Project description

Python Spidev

This project contains a python module for interfacing with SPI devices from user space via the spidev linux kernel driver.

This is a modified version of the code originally found [here](

All code is GPLv2 licensed unless explicitly stated otherwise.


import spidev
spi = spidev.SpiDev(), device)
to_send = [0x01, 0x02, 0x03]

import spidev
spi = spidev.SpiDev(), device)

# Settings (for example)
spi.max_speed_hz = 5000
spi.mode = 0b01


* `bits_per_word`
* `cshigh`
* `loop`
* `lsbfirst`
* `max_speed_hz`
* `mode` - SPI mode as two bit pattern of clock polarity and phase [CPOL|CPHA], min: 0b00 = 0, max: 0b11 = 3
* `threewire` - SI/SO signals shared


open(bus, device)

Connects to the specified SPI device, opening /dev/spidev-bus.device


Read n bytes from SPI device.

writebytes(list of values)

Writes a list of values to SPI device.

xfer(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be released and reactivated between blocks.
Delay specifies the delay in usec between blocks.

xfer2(list of values[, speed_hz, delay_usec, bits_per_word])

Performs an SPI transaction. Chip-select should be held active between blocks.


Disconnects from the SPI device.



* Fixed and formatting, hopefully


* Memset fix recommended by Dougie Lawson
* Fixes for Kernel 3.15+ from
* Fixes for Python 3/2 compatibility.
* Added subclassing support -


Code sourced from
and modified.

Pre 2.0

spimodule.c originally uathored by Volker Thoms, 2009.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for spidev, version 3.2
Filename, size File type Python version Upload date Hashes
Filename, size spidev-3.2.tar.gz (12.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page