+from collections import namedtuple
+
+Data = namedtuple('Data', ['ss', 'es', 'val'])
+
+'''
+OUTPUT_PYTHON format:
+
+Packet:
+[<ptype>, <data1>, <data2>]
+
+<ptype>:
+ - 'DATA': <data1> contains the MOSI data, <data2> contains the MISO data.
+ The data is _usually_ 8 bits (but can also be fewer or more bits).
+ Both data items are Python numbers (not strings), or None if the respective
+ channel was not supplied.
+ - 'BITS': <data1>/<data2> contain a list of bit values in this MOSI/MISO data
+ item, and for each of those also their respective start-/endsample numbers.
+ - 'CS-CHANGE': <data1> is the old CS# pin value, <data2> is the new value.
+ Both data items are Python numbers (0/1), not strings. At the beginning of
+ the decoding a packet is generated with <data1> = None and <data2> being the
+ initial state of the CS# pin or None if the chip select pin is not supplied.
+ - 'TRANSFER': <data1>/<data2> contain a list of Data() namedtuples for each
+ byte transferred during this block of CS# asserted time. Each Data() has
+ fields ss, es, and val.
+
+Examples:
+ ['CS-CHANGE', None, 1]
+ ['CS-CHANGE', 1, 0]
+ ['DATA', 0xff, 0x3a]
+ ['BITS', [[1, 80, 82], [1, 83, 84], [1, 85, 86], [1, 87, 88],
+ [1, 89, 90], [1, 91, 92], [1, 93, 94], [1, 95, 96]],
+ [[0, 80, 82], [1, 83, 84], [0, 85, 86], [1, 87, 88],
+ [1, 89, 90], [1, 91, 92], [0, 93, 94], [0, 95, 96]]]
+ ['DATA', 0x65, 0x00]
+ ['DATA', 0xa8, None]
+ ['DATA', None, 0x55]
+ ['CS-CHANGE', 0, 1]
+ ['TRANSFER', [Data(ss=80, es=96, val=0xff), ...],
+ [Data(ss=80, es=96, val=0x3a), ...]]
+'''