Requirements
Python >= 3.7 is required. On older distributions where this version is not available, build Retis without Python support:Core Python Classes
The Python bindings provide the following classes for inspecting Retis events:Event
Event
Python representation of a Retis event with helpers to access sections and their data.
EventSeries
EventSeries
Python representation of a series of sorted events from
retis sort -o. Implements the iterator protocol.EventReader
EventReader
Reads a file created by
retis collect and iterates over events.SeriesReader
SeriesReader
Reads a file created by
retis sort and iterates over event series.EventFile
EventFile
Automatically determines if a file is sorted or unsorted and creates appropriate reader instances.
Built-in Python Interpreter
The built-in interpreter executes Python scripts with automatic access to event data through a globalreader variable of type EventFile.
Basic Script Execution
Script Storage Locations
Store scripts in these directories to execute by name:$HOME/.config/retis/python/usr/share/retis/python
Interactive Shell
Launch an interactive Python shell with automatic event file access:Working with Sorted Files
Command Line Arguments
Scripts have full access tosys.argv and can use standard modules like argparse:
External Python Library
For sophisticated programs requiring control over the Python environment, use the retis package on PyPI.Installation
Example: Series Statistics
Parsing Packet Data
Packet data is stored raw in Retis events. Use a third-party library like Scapy to parse individual packet fields.
Using Scapy Helper
Retis provides ato_scapy() helper to convert raw packets to Scapy Ether objects:
Importing Scapy
Raw Packet Access
Access raw packet data as bytes for custom parsing:Available Helpers
Event Sections
Event Display
SKB Tracking
See Also
- Event Structure - Understanding Retis event JSON structure
- PCAP Export - Exporting events to PCAP format
