Python bindings

The Python bindings use Boost to interact with SPDLib.

The Python bindings doesn't work - what now?

I had the following problem when I had finished the installation of SPDLib and the installation of the Python bindings. The path to the site-packages catalog need to be set as environmental variable:


This can be done permanently by editing the .profile which is located in your home-folder:

gedit ~/.profile


export PYTHONPATH=${PYTHONPATH}:/usr/local/site-packages

Another way is to do it inside Python, but it need to be everytime you start Python then.

import sys

How to get help?

Python has a built in help system which you can use for support. Try running the following commands to view the basic python generated help for spdpy.

>>> import spdpy
>>> help(spdpy)

This help system lists all the functions and classes available within the python bindings for SPDLib. Unfortunately, the variable names have not been included and reading of the documentation below or looking directly within the C++ file spdpy.cpp is required for more details of the function inputs and outputs.

Python Classes and Functions

There are five python classes which are provided to create the SPD python bind, in addition a series of independent functions are provided to simplify the accessing of data.

The available classes are:

  • SPDFile - Represents the SPD/UPD file header parameters, see SPD for field names
  • SPDPointPy - An SPD Point, see SPD for field names
  • SPDPulsePy - An SPD Pulse, see SPD for field names
  • SPDWriter - Allows a SPD file to be written
  • UPDWriter - Allows a UPD file to be written

Additionally the following functions are available:

  • printSPDFile()
  • copySPDFileAttributes()
  • openSPDFileHeader()
  • openUPDFileHeader()
  • readUPD()
  • readSPDHeaderRow()
  • readSPDPulsesRow()
  • readSPDPulsesRowCols()
  • readSPDPulsesOffset()
  • readSPDPulsesIntoBlock()
  • readSPDPulsesIntoBlockList()
  • createSPDFile()
  • createSPDPulsePy()
  • createSPDPointPy()


Prints the SPD File header information - similar to spdinfo command.

printSPDFile(string filepath)


Copy the SPDFile header parameters into a new SPDFile object with file path 'newSPDFilePath'.

SPDFile copySPDFileAttributes(SPDFile spdFile, string newSPDFilePath)


Opens and reads the attributes of an SPD file into a SPDFile class object.

openSPDFileHeader(string filepath)


Opens and reads the attributes of an UPD file into a SPDFile class object.

openUPDFileHeader(string filepath)


Read pulses from a UPD file.

list readUPD(SPDFile spdFile, int start, int numPulses)


Read the SPD index header information.

readSPDHeaderRow(SPDFile spdFile, int row, list binOffsets, list numPulsesInBins)


Read pulses for a row. The output is a list of lists (i.e., a list for each bin in the row).

list readSPDPulsesRow(SPDFile spdFile, int row)


Read all the pulses on a row from start column to end column into a single list.

list readSPDPulsesRowCols(SPDFile spdFile, int row, int startCol, int endCol)


Read a number of pulses from an offset within the SPD file.

list readSPDPulsesOffset(SPDFile spdFile, int offset, int numPulses)


Read a block of data into a list of lists (i.e., one list for each column).

// BBOX = [startX, startY, endX, endY]
list readSPDPulsesIntoBlock(SPDFile spdFile, list bbox)


Read a block of data into a single list.

// BBOX = [startX, startY, endX, endY]
list readSPDPulsesIntoBlockList(SPDFile spdFile, list bbox)


Creates a new SPDFile object which can be used to create either a UPD or SPD file at location 'filepath'.

createSPDFile(string filepath)


Creates a python SPDPulse with default values.



Creates a python SPDPoint with default values.



A range of examples have been provided, see list below: