realtime_api
¶
pupil_labs.realtime_api package.
Python Client for the Pupil Labs Real-Time API
Modules:
-
base
– -
device
– -
discovery
– -
models
– -
simple
– -
streaming
– -
time_echo
–Manual time offset estimation via the Pupil Labs Time Echo protocol.
Classes:
-
APIPath
–API endpoint paths for the Realtime API.
-
BlinkEventData
–Data for a blink event.
-
Device
–Class representing a Pupil Labs device.
-
DeviceError
–Exception raised when a device operation fails.
-
DualMonocularGazeData
–Experimental class for dual monocular gaze data.
-
EyestateGazeData
–Gaze data with additional eye state information.
-
FixationEventData
–Data for a fixation or saccade event.
-
FixationOnsetEventData
–Data for a fixation or saccade onset event.
-
GazeData
–Basic gaze data with position, timestamp and indicator of glasses worn status.
-
Network
–Network discovery client for finding devices.
-
RTSPData
–Container for RTSP data with timestamp information.
-
RTSPEyeEventStreamer
–Stream and parse eye events from an RTSP source.
-
RTSPGazeStreamer
–Stream and parse gaze data from an RTSP source.
-
RTSPImuStreamer
–Stream and parse IMU data from an RTSP source.
-
RTSPRawStreamer
–Stream raw data from an RTSP source.
-
RTSPVideoFrameStreamer
–Stream and decode video frames from an RTSP source.
-
StatusUpdateNotifier
–Helper class for handling device status update callbacks.
-
VideoFrame
–A video frame with timestamp information.
Functions:
-
discover_devices
–Use Bonjour to find devices in the local network that serve the Realtime API.
-
receive_eye_events_data
–Receive eye events data from an RTSP stream.
-
receive_gaze_data
–Receive gaze data from an RTSP stream.
-
receive_imu_data
–Receive IMU data from a given RTSP URL.
-
receive_raw_rtsp_data
–Receive raw data from an RTSP stream.
-
receive_video_frames
–Receive video frames from an RTSP stream.
APIPath
¶
Bases: Enum
API endpoint paths for the Realtime API.
This enum defines the various API endpoints that can be accessed through the Realtime API.
Methods:
-
full_address
–Construct a full URL for this API endpoint.
full_address
¶
Construct a full URL for this API endpoint.
Source code in src/pupil_labs/realtime_api/models.py
47 48 49 50 51 |
|
BlinkEventData
¶
Bases: NamedTuple
Data for a blink event.
Represents a detected blink event with timing information.
Methods:
-
from_raw
–Create a BlinkEventData instance from raw RTSP data.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
end_time_ns
(int
) –End time of the blink in nanoseconds.
-
event_type
(int
) –Type of event (4 -> blink events).
-
rtp_ts_unix_seconds
(float
) –RTP timestamp in seconds since Unix epoch.
-
start_time_ns
(int
) –Start time of the blink in nanoseconds.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since the Unix epoch.
rtp_ts_unix_seconds
instance-attribute
¶
rtp_ts_unix_seconds: float
RTP timestamp in seconds since Unix epoch.
timestamp_unix_ns
property
¶
timestamp_unix_ns: int
Get the timestamp in nanoseconds since the Unix epoch.
from_raw
classmethod
¶
from_raw(data: RTSPData) -> BlinkEventData
Create a BlinkEventData instance from raw RTSP data.
Source code in src/pupil_labs/realtime_api/streaming/eye_events.py
27 28 29 30 31 32 33 34 35 |
|
Device
¶
Bases: DeviceBase
Class representing a Pupil Labs device.
This class provides methods to interact with the device, such as starting and stopping recordings, sending events, and fetching device status. It also provides a context manager for automatically closing the device session.
Methods:
-
api_url
–Construct a full API URL for the given path.
-
close
–Close the connection to the device.
-
convert_from
–Convert another device instance to this type.
-
from_discovered_device
–Create a device instance from discovery information.
-
get_calibration
–Get the current cameras calibration data.
-
get_status
–Get the current status of the device.
-
get_template
–Get the template currently selected on device.
-
get_template_data
–Get the template data entered on device.
-
post_template_data
–Set the data for the currently selected template.
-
recording_cancel
–Cancel the current recording without saving it.
-
recording_start
–Start a recording on the device.
-
recording_stop_and_save
–Stop and save the current recording.
-
send_event
–Send an event to the device.
-
status_updates
–Stream status updates from the device.
Attributes:
-
active_session
(ClientSession
) –Returns the active session, raising an error if it's None.
-
session
(ClientSession | None
) –The HTTP session used for making requests.
-
template_definition
(Template | None
) –The template definition currently selected on the device.
Source code in src/pupil_labs/realtime_api/device.py
74 75 76 77 |
|
active_session
property
¶
active_session: ClientSession
Returns the active session, raising an error if it's None.
session
instance-attribute
¶
session: ClientSession | None
The HTTP session used for making requests.
template_definition
class-attribute
instance-attribute
¶
template_definition: Template | None = None
The template definition currently selected on the device.
api_url
¶
Construct a full API URL for the given path.
Parameters:
-
path
(APIPath
) –API path to access.
-
protocol
(str
, default:'http'
) –Protocol to use (http).
-
prefix
(str
, default:'/api'
) –API URL prefix.
Returns:
-
str
–Complete URL for the API endpoint.
Source code in src/pupil_labs/realtime_api/base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
close
async
¶
close() -> None
Close the connection to the device.
Source code in src/pupil_labs/realtime_api/device.py
336 337 338 339 |
|
convert_from
classmethod
¶
convert_from(other: T) -> DeviceType
Convert another device instance to this type.
Parameters:
-
other
(T
) –Device instance to convert.
Returns:
-
DeviceType
–Converted device instance.
Source code in src/pupil_labs/realtime_api/base.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
from_discovered_device
classmethod
¶
from_discovered_device(device: DiscoveredDeviceInfo) -> DeviceType
Create a device instance from discovery information.
Parameters:
-
device
(DiscoveredDeviceInfo
) –Discovered device information.
Returns:
-
DeviceType
–Device instance
Source code in src/pupil_labs/realtime_api/base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
get_calibration
async
¶
get_calibration() -> Calibration
Get the current cameras calibration data.
Note that Pupil Invisible and Neon are calibration free systems, this refers to the intrinsincs and extrinsics of the cameras and is only available for Neon.
Returns:
-
Calibration
–pupil_labs.neon_recording.calib.Calibration: The calibration data.
Raises:
-
DeviceError
–If the request fails.
Source code in src/pupil_labs/realtime_api/device.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
get_status
async
¶
get_status() -> Status
Get the current status of the device.
Returns:
-
Status
(Status
) –The current device status.
Raises:
-
DeviceError
–If the request fails.
Source code in src/pupil_labs/realtime_api/device.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
get_template
async
¶
get_template() -> Template
Get the template currently selected on device.
Returns:
-
Template
(Template
) –The currently selected template.
Raises:
-
DeviceError
–If the template can't be fetched.
Source code in src/pupil_labs/realtime_api/device.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_template_data
async
¶
get_template_data(template_format: TemplateDataFormat = 'simple') -> Any
Get the template data entered on device.
Parameters:
-
template_format
(TemplateDataFormat
, default:'simple'
) –Format of the returned data. - "api" returns the data as is from the api e.g., {"item_uuid": ["42"]} - "simple" returns the data parsed e.g., {"item_uuid": 42}
Returns:
-
Any
–The template data in the requested format.
Raises:
-
DeviceError
–If the template's data could not be fetched.
-
AssertionError
–If an invalid format is provided.
Source code in src/pupil_labs/realtime_api/device.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
post_template_data
async
¶
post_template_data(template_answers: dict[str, list[str]], template_format: TemplateDataFormat = 'simple') -> Any
Set the data for the currently selected template.
Parameters:
-
template_answers
(dict[str, list[str]]
) –The template data to send.
-
template_format
(TemplateDataFormat
, default:'simple'
) –Format of the input data. - "api" accepts the data as in realtime api format e.g., {"item_uuid": ["42"]} - "simple" accepts the data in parsed format e.g., {"item_uuid": 42}
Returns:
-
Any
–The result of the operation.
Raises:
-
DeviceError
–If the data can not be sent.
-
ValueError
–If invalid data type.
-
AssertionError
–If an invalid format is provided.
Source code in src/pupil_labs/realtime_api/device.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
recording_cancel
async
¶
recording_cancel() -> None
Cancel the current recording without saving it.
Raises:
-
DeviceError
–If the recording could not be cancelled. Possible reasons include: - Recording not running
Source code in src/pupil_labs/realtime_api/device.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
recording_start
async
¶
recording_start() -> str
Start a recording on the device.
Returns:
-
str
(str
) –ID of the started recording.
Raises:
-
DeviceError
–If recording could not be started. Possible reasons include: - Recording already running - Template has required fields - Low battery - Low storage - No wearer selected - No workspace selected - Setup bottom sheets not completed
Source code in src/pupil_labs/realtime_api/device.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
recording_stop_and_save
async
¶
recording_stop_and_save() -> None
Stop and save the current recording.
Raises:
-
DeviceError
–If recording could not be stopped. Possible reasons include: - Recording not running - Template has required fields
Source code in src/pupil_labs/realtime_api/device.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
send_event
async
¶
Send an event to the device.
Parameters:
-
event_name
(str
) –Name of the event.
-
event_timestamp_unix_ns
(int | None
, default:None
) –Optional timestamp in unix nanoseconds. If None, the current time will be used.
Returns:
-
Event
(Event
) –The created event.
Raises:
-
DeviceError
–If sending the event fails.
Source code in src/pupil_labs/realtime_api/device.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
status_updates
async
¶
status_updates() -> AsyncIterator[Component]
Stream status updates from the device.
Yields:
-
Component
(AsyncIterator[Component]
) –Status update components as they arrive.
Auto-reconnect, see: https://websockets.readthedocs.io/en/stable/reference/asyncio/client.html#websockets.asyncio.client.connect
Source code in src/pupil_labs/realtime_api/device.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
DualMonocularGazeData
¶
Bases: NamedTuple
Experimental class for dual monocular gaze data.
Contains separate gaze points for left and right eyes.
Methods:
-
from_raw
–Create a DualMonocularGazeData instance from raw data.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
left
(Point
) –Gaze point for the left eye.
-
right
(Point
) –Gaze point for the right eye.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since Unix epoch.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since Unix epoch.
-
worn
(bool
) –Whether the glasses are being worn.
timestamp_unix_ns
property
¶
timestamp_unix_ns: int
Get the timestamp in nanoseconds since Unix epoch.
timestamp_unix_seconds
instance-attribute
¶
timestamp_unix_seconds: float
Timestamp in seconds since Unix epoch.
from_raw
classmethod
¶
from_raw(data: RTSPData) -> DualMonocularGazeData
Create a DualMonocularGazeData instance from raw data.
Parameters:
-
data
(RTSPData
) –The raw data received from the RTSP stream.
Returns:
-
DualMonocularGazeData
(DualMonocularGazeData
) –An instance of DualMonocularGazeData with the parsed values.
Source code in src/pupil_labs/realtime_api/streaming/gaze.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
EyestateGazeData
¶
Bases: NamedTuple
Gaze data with additional eye state information.
Contains gaze point, pupil diameter, eyeball center coordinates, and optical axis coordinates for both left and right eyes.
Methods:
-
from_raw
–Create an EyestateGazeData instance from raw data.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
eyeball_center_left_x
(float
) –X coordinate of the eyeball center for the left eye.
-
eyeball_center_left_y
(float
) –Y coordinate of the eyeball center for the left eye.
-
eyeball_center_left_z
(float
) –Z coordinate of the eyeball center for the left eye.
-
eyeball_center_right_x
(float
) –X coordinate of the eyeball center for the right eye.
-
eyeball_center_right_y
(float
) –Y coordinate of the eyeball center for the right eye.
-
eyeball_center_right_z
(float
) –Z coordinate of the eyeball center for the right eye.
-
optical_axis_left_x
(float
) –X coordinate of the optical axis for the left eye.
-
optical_axis_left_y
(float
) –Y coordinate of the optical axis for the left eye.
-
optical_axis_left_z
(float
) –Z coordinate of the optical axis for the left eye.
-
optical_axis_right_x
(float
) –X coordinate of the optical axis for the right eye.
-
optical_axis_right_y
(float
) –Y coordinate of the optical axis for the right eye.
-
optical_axis_right_z
(float
) –Z coordinate of the optical axis for the right eye.
-
pupil_diameter_left
(float
) –Pupil diameter for the left eye.
-
pupil_diameter_right
(float
) –Pupil diameter for the right eye.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since Unix epoch.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since Unix epoch.
-
worn
(bool
) –Whether the glasses are being worn.
-
x
(float
) –X coordinate of the gaze point.
-
y
(float
) –Y coordinate of the gaze point.
eyeball_center_left_x
instance-attribute
¶
eyeball_center_left_x: float
X coordinate of the eyeball center for the left eye.
eyeball_center_left_y
instance-attribute
¶
eyeball_center_left_y: float
Y coordinate of the eyeball center for the left eye.
eyeball_center_left_z
instance-attribute
¶
eyeball_center_left_z: float
Z coordinate of the eyeball center for the left eye.
eyeball_center_right_x
instance-attribute
¶
eyeball_center_right_x: float
X coordinate of the eyeball center for the right eye.
eyeball_center_right_y
instance-attribute
¶
eyeball_center_right_y: float
Y coordinate of the eyeball center for the right eye.
eyeball_center_right_z
instance-attribute
¶
eyeball_center_right_z: float
Z coordinate of the eyeball center for the right eye.
optical_axis_left_x
instance-attribute
¶
optical_axis_left_x: float
X coordinate of the optical axis for the left eye.
optical_axis_left_y
instance-attribute
¶
optical_axis_left_y: float
Y coordinate of the optical axis for the left eye.
optical_axis_left_z
instance-attribute
¶
optical_axis_left_z: float
Z coordinate of the optical axis for the left eye.
optical_axis_right_x
instance-attribute
¶
optical_axis_right_x: float
X coordinate of the optical axis for the right eye.
optical_axis_right_y
instance-attribute
¶
optical_axis_right_y: float
Y coordinate of the optical axis for the right eye.
optical_axis_right_z
instance-attribute
¶
optical_axis_right_z: float
Z coordinate of the optical axis for the right eye.
pupil_diameter_left
instance-attribute
¶
pupil_diameter_left: float
Pupil diameter for the left eye.
pupil_diameter_right
instance-attribute
¶
pupil_diameter_right: float
Pupil diameter for the right eye.
timestamp_unix_ns
property
¶
timestamp_unix_ns: int
Get the timestamp in nanoseconds since Unix epoch.
timestamp_unix_seconds
instance-attribute
¶
timestamp_unix_seconds: float
Timestamp in seconds since Unix epoch.
from_raw
classmethod
¶
from_raw(data: RTSPData) -> EyestateGazeData
Create an EyestateGazeData instance from raw data.
Parameters:
-
data
(RTSPData
) –The raw data received from the RTSP stream.
Returns:
-
EyestateGazeData
(EyestateGazeData
) –An instance of EyestateGazeData with the parsed values.
Source code in src/pupil_labs/realtime_api/streaming/gaze.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
FixationEventData
¶
Bases: NamedTuple
Data for a fixation or saccade event.
Represents a completed fixation or saccade event with detailed information.
Methods:
-
from_raw
–Create a FixationEventData instance from raw RTSP data.
Attributes:
-
amplitude_angle_deg
(float
) –Amplitude in degrees.
-
amplitude_pixels
(float
) –Amplitude in pixels.
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
end_gaze_x
(float
) –End gaze x-coordinate in pixels.
-
end_gaze_y
(float
) –End gaze y-coordinate in pixels.
-
end_time_ns
(int
) –End time of the event in nanoseconds.
-
event_type
(int
) –Type of event (0 for saccade, 1 for fixation).
-
max_velocity
(float
) –Maximum velocity in pixels per degree.
-
mean_gaze_x
(float
) –Mean gaze x-coordinate in pixels.
-
mean_gaze_y
(float
) –Mean gaze y-coordinate in pixels.
-
mean_velocity
(float
) –Mean velocity in pixels per degree.
-
rtp_ts_unix_seconds
(float
) –RTP timestamp in seconds since Unix epoch.
-
start_gaze_x
(float
) –Start gaze x-coordinate in pixels.
-
start_gaze_y
(float
) –Start gaze y-coordinate in pixels.
-
start_time_ns
(int
) –Start time of the event in nanoseconds.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since the Unix epoch.
rtp_ts_unix_seconds
instance-attribute
¶
rtp_ts_unix_seconds: float
RTP timestamp in seconds since Unix epoch.
timestamp_unix_ns
property
¶
timestamp_unix_ns: int
Get the timestamp in nanoseconds since the Unix epoch.
from_raw
classmethod
¶
from_raw(data: RTSPData) -> FixationEventData
Create a FixationEventData instance from raw RTSP data.
Source code in src/pupil_labs/realtime_api/streaming/eye_events.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
FixationOnsetEventData
¶
Bases: NamedTuple
Data for a fixation or saccade onset event.
Represents the beginning of a fixation or saccade event.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
event_type
(int
) –Type of event (2 for saccade onset, 3 for fixation onset).
-
rtp_ts_unix_seconds
(float
) –RTP timestamp in seconds since Unix epoch.
-
start_time_ns
(int
) –Start time of the event in nanoseconds.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since the Unix epoch.
GazeData
¶
Bases: NamedTuple
Basic gaze data with position, timestamp and indicator of glasses worn status.
Represents the 2D gaze point on the scene camera coordinates with a timestamp in nanoseconds unix epoch and an indicator of whether the glasses are being worn.
Methods:
-
from_raw
–Create a GazeData instance from raw data.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since Unix epoch.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since Unix epoch.
-
worn
(bool
) –Whether the glasses are being worn.
-
x
(float
) –"X coordinate of the gaze point
-
y
(float
) –Y coordinate of the gaze point.
timestamp_unix_ns
property
¶
timestamp_unix_ns: int
Get the timestamp in nanoseconds since Unix epoch.
timestamp_unix_seconds
instance-attribute
¶
timestamp_unix_seconds: float
Timestamp in seconds since Unix epoch.
from_raw
classmethod
¶
Create a GazeData instance from raw data.
Parameters:
-
data
(RTSPData
) –The raw data received from the RTSP stream.
Returns:
-
GazeData
(GazeData
) –An instance of GazeData with the parsed values.
Source code in src/pupil_labs/realtime_api/streaming/gaze.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Network
¶
Network()
Network discovery client for finding devices.
This class manages device discovery on the local network using Zeroconf/Bonjour. It maintains a list of discovered devices and provides methods to access them.
Attributes:
-
_devices
(dict | None
) –A dictionary of discovered devices, where the keys are device names and the values are DiscoveredDeviceInfo objects.
-
_new_devices
(Queue
) –A queue to hold newly discovered devices.
-
_aiozeroconf
(AsyncZeroconf | None
) –An instance of AsyncZeroconf for network discovery.
-
_aiobrowser
(AsyncServiceBrowser | None
) –An instance of AsyncServiceBrowser for browsing services on the network.
-
_open
(bool
) –A flag indicating whether the network discovery client is open.
Methods:
-
close
–Close all network resources.
-
wait_for_new_device
–Wait for a new device to be discovered.
Source code in src/pupil_labs/realtime_api/discovery.py
33 34 35 36 37 38 39 40 41 42 |
|
close
async
¶
close() -> None
Close all network resources.
This method stops the Zeroconf browser, closes connections, and clears the device list.
Source code in src/pupil_labs/realtime_api/discovery.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
wait_for_new_device
async
¶
wait_for_new_device(timeout_seconds: float | None = None) -> DiscoveredDeviceInfo | None
Wait for a new device to be discovered.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new device. If None, wait indefinitely.
Returns:
-
DiscoveredDeviceInfo | None
–Optional[DiscoveredDeviceInfo]: The newly discovered device, or None if the timeout was reached.
Source code in src/pupil_labs/realtime_api/discovery.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
RTSPData
¶
Bases: NamedTuple
Container for RTSP data with timestamp information.
Attributes:
-
datetime
(datetime
) –Get the timestamp as a datetime object.
-
raw
(ByteString
) –Raw binary data received from the RTSP stream.
-
timestamp_unix_ns
(int
) –Get the timestamp in nanoseconds since the Unix epoch.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since the Unix epoch from RTCP SR packets.
RTSPEyeEventStreamer
¶
Bases: RTSPRawStreamer
Stream and parse eye events from an RTSP source.
This class extends RTSPRawStreamer to parse raw RTSP data into structured eye event data objects.
Methods:
-
receive
–Receive and parse eye events from the RTSP stream.
Attributes:
-
encoding
(str
) –Get the encoding of the RTSP stream.
-
reader
(_WallclockRTSPReader
) –Get the underlying RTSP reader.
Source code in src/pupil_labs/realtime_api/streaming/base.py
78 79 80 |
|
encoding
property
¶
encoding: str
Get the encoding of the RTSP stream.
Returns:
-
str
(str
) –The encoding name in lowercase.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing or incomplete.
receive
async
¶
receive() -> AsyncIterator[FixationEventData | FixationOnsetEventData | BlinkEventData]
Receive and parse eye events from the RTSP stream.
Yields:
-
AsyncIterator[FixationEventData | FixationOnsetEventData | BlinkEventData]
–FixationEventData | FixationOnsetEventData | BlinkEventData: Parsed eye event data.
Raises:
-
KeyError
–If the event type is not recognized.
-
Exception
–If there is an error parsing the event data.
Source code in src/pupil_labs/realtime_api/streaming/eye_events.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
RTSPGazeStreamer
¶
Bases: RTSPRawStreamer
Stream and parse gaze data from an RTSP source.
This class extends RTSPRawStreamer to parse raw RTSP data into structured gaze data objects. The specific type of gaze data is determined by the length of the raw data packet.
Methods:
-
receive
–Receive and parse gaze data from the RTSP stream.
Attributes:
-
encoding
(str
) –Get the encoding of the RTSP stream.
-
reader
(_WallclockRTSPReader
) –Get the underlying RTSP reader.
Source code in src/pupil_labs/realtime_api/streaming/base.py
78 79 80 |
|
encoding
property
¶
encoding: str
Get the encoding of the RTSP stream.
Returns:
-
str
(str
) –The encoding name in lowercase.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing or incomplete.
receive
async
¶
receive() -> AsyncIterator[GazeDataType]
Receive and parse gaze data from the RTSP stream.
Yields:
-
AsyncIterator[GazeDataType]
–GazeDataType
-
AsyncIterator[GazeDataType]
–Parsed gaze data of various types. The type of gaze data object is
-
AsyncIterator[GazeDataType]
–determined by the length of the raw data packet:
- 9 bytes: GazeData (basic gaze position)
- 17 bytes: DualMonocularGazeData (left and right eye positions)
- 65 bytes: EyestateGazeData (gaze with eye state)
- 89 bytes: EyestateEyelidGazeData (gaze with eye state and eyelid info)
Raises:
-
KeyError
–If the data length does not match any known format.
-
Exception
–If there is an error parsing the gaze data.
Source code in src/pupil_labs/realtime_api/streaming/gaze.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
RTSPImuStreamer
¶
Bases: RTSPRawStreamer
Stream and parse IMU data from an RTSP source.
This class extends RTSPRawStreamer to parse raw RTSP data into structured IMU data objects.
Methods:
-
receive
–Receive and parse IMU data from the RTSP stream.
Attributes:
-
encoding
(str
) –Get the encoding of the RTSP stream.
-
reader
(_WallclockRTSPReader
) –Get the underlying RTSP reader.
Source code in src/pupil_labs/realtime_api/streaming/base.py
78 79 80 |
|
encoding
property
¶
encoding: str
Get the encoding of the RTSP stream.
Returns:
-
str
(str
) –The encoding name in lowercase.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing or incomplete.
receive
async
¶
receive() -> AsyncIterator[IMUData]
Receive and parse IMU data from the RTSP stream.
This method parses the raw binary data into IMUData objects by using the protobuf deserializer.
Yields:
-
IMUData
(AsyncIterator[IMUData]
) –Parsed IMU data.
Raises:
-
Exception
–If there is an error parsing the IMU data.
Source code in src/pupil_labs/realtime_api/streaming/imu.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
RTSPRawStreamer
¶
Stream raw data from an RTSP source.
This class connects to an RTSP source and provides access to the raw data with timestamps synchronized to the device's clock.
All constructor arguments are forwarded to the underlying aiortsp.rtsp.reader.RTSPReader.
Methods:
-
receive
–Receive raw data from the RTSP stream.
Attributes:
-
encoding
(str
) –Get the encoding of the RTSP stream.
-
reader
(_WallclockRTSPReader
) –Get the underlying RTSP reader.
Source code in src/pupil_labs/realtime_api/streaming/base.py
78 79 80 |
|
encoding
property
¶
encoding: str
Get the encoding of the RTSP stream.
Returns:
-
str
(str
) –The encoding name in lowercase.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing or incomplete.
receive
async
¶
receive() -> AsyncIterator[RTSPData]
Receive raw data from the RTSP stream.
This method yields RTSPData objects containing the raw data and corresponding timestamps.
Source code in src/pupil_labs/realtime_api/streaming/base.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
RTSPVideoFrameStreamer
¶
Bases: RTSPRawStreamer
Stream and decode video frames from an RTSP source.
This class extends RTSPRawStreamer to parse raw RTSP data into video frames using the pupil_labs.video and pyav library for decoding.
Attributes:
-
_sprop_parameter_set_payloads
(list[ByteString] | None
) –Cached SPS/PPS parameters for the H.264 codec.
Methods:
-
receive
–Receive and decode video frames from the RTSP stream.
Source code in src/pupil_labs/realtime_api/streaming/video.py
93 94 95 |
|
encoding
property
¶
encoding: str
Get the encoding of the RTSP stream.
Returns:
-
str
(str
) –The encoding name in lowercase.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing or incomplete.
sprop_parameter_set_payloads
property
¶
sprop_parameter_set_payloads: list[ByteString] | None
Get the SPS/PPS parameter set payloads for the H.264 codec.
These parameters are extracted from the SDP data and are required for initializing the H.264 decoder.
Returns:
-
list[ByteString] | None
–list[ByteString]: List of parameter set payloads.
Raises:
-
SDPDataNotAvailableError
–If SDP data is missing required fields.
receive
async
¶
receive() -> AsyncIterator[VideoFrame]
Receive and decode video frames from the RTSP stream.
Source code in src/pupil_labs/realtime_api/streaming/video.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
StatusUpdateNotifier
¶
StatusUpdateNotifier(device: Device, callbacks: list[UpdateCallback])
Helper class for handling device status update callbacks.
This class manages the streaming of status updates from a device and dispatches them to registered callbacks.
Attributes:
-
_auto_update_task
(Task | None
) –Task for the update loop.
-
_device
(Device
) –The device to get updates from.
-
_callbacks
(list[UpdateCallback]
) –List of callbacks to invoke.
Methods:
-
receive_updates_start
–Start receiving status updates.
-
receive_updates_stop
–Stop receiving status updates.
Source code in src/pupil_labs/realtime_api/device.py
408 409 410 411 |
|
receive_updates_start
async
¶
receive_updates_start() -> None
Start receiving status updates.
This method starts the background task that receives updates and dispatches them to registered callbacks.
Source code in src/pupil_labs/realtime_api/device.py
413 414 415 416 417 418 419 420 421 422 |
|
receive_updates_stop
async
¶
receive_updates_stop() -> None
Stop receiving status updates.
This method cancels the background task that receives updates.
Source code in src/pupil_labs/realtime_api/device.py
424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
VideoFrame
¶
Bases: NamedTuple
A video frame with timestamp information.
This class represents a video frame from the scene camera with associated timestamp information. The Class inherits VideoFrame from py.av library.
Methods:
-
bgr_buffer
–Convert the video frame to a BGR buffer.
-
to_ndarray
–Convert the video frame to a NumPy array.
Attributes:
-
av_frame
(VideoFrame
) –The video frame.
-
datetime
(datetime
) –Get timestamp as a datetime object.
-
timestamp_unix_ns
(int
) –Get timestamp in nanoseconds since Unix epoch.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since Unix epoch.
timestamp_unix_seconds
instance-attribute
¶
timestamp_unix_seconds: float
Timestamp in seconds since Unix epoch.
bgr_buffer
¶
bgr_buffer() -> BGRBuffer
Convert the video frame to a BGR buffer.
This method converts the video frame to a BGR buffer, which is a NumPy array with the shape (height, width, 3) and dtype uint8. The BGR format is commonly used in computer vision applications.
Returns:
-
BGRBuffer
(BGRBuffer
) –The BGR buffer as a NumPy array.
Source code in src/pupil_labs/realtime_api/streaming/video.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
to_ndarray
¶
Convert the video frame to a NumPy array.
Source code in src/pupil_labs/realtime_api/streaming/video.py
42 43 44 |
|
discover_devices
async
¶
discover_devices(timeout_seconds: float | None = None) -> AsyncIterator[DiscoveredDeviceInfo]
Use Bonjour to find devices in the local network that serve the Realtime API.
This function creates a temporary network discovery client and yields discovered devices as they are found.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Stop after
timeout_seconds
. IfNone
, run discovery forever.
Yields:
-
DiscoveredDeviceInfo
(AsyncIterator[DiscoveredDeviceInfo]
) –Information about discovered devices.
Example
async for device in discover_devices(timeout_seconds=10.0):
print(f"Found device: {device.name} at {device.addresses[0]}:{device.port}")
Source code in src/pupil_labs/realtime_api/discovery.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
receive_eye_events_data
async
¶
receive_eye_events_data(url: str, *args: Any, **kwargs: Any) -> AsyncIterator[FixationEventData | FixationOnsetEventData | BlinkEventData]
Receive eye events data from an RTSP stream.
This is a convenience function that creates an RTSPEyeEventStreamer and yields parsed eye event data.
Parameters:
-
url
(str
) –RTSP URL to connect to.
-
*args
(Any
, default:()
) –Additional positional arguments passed to RTSPEyeEventStreamer.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments passed to RTSPEyeEventStreamer.
Yields:
-
FixationEventData
(AsyncIterator[FixationEventData | FixationOnsetEventData | BlinkEventData]
) –Parsed fixation event data.
Source code in src/pupil_labs/realtime_api/streaming/eye_events.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
receive_gaze_data
async
¶
receive_gaze_data(url: str, *args: Any, **kwargs: Any) -> AsyncIterator[GazeDataType]
Receive gaze data from an RTSP stream.
This is a convenience function that creates an RTSPGazeStreamer and yields parsed gaze data.
Parameters:
-
url
(str
) –RTSP URL to connect to.
-
*args
(Any
, default:()
) –Additional positional arguments passed to RTSPGazeStreamer.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments passed to RTSPGazeStreamer.
Yields:
-
GazeDataType
(AsyncIterator[GazeDataType]
) –Parsed gaze data of various types.
-
AsyncIterator[GazeDataType]
–The type of gaze data object is determined by the length of the raw data packet:
-
AsyncIterator[GazeDataType]
–- 9 bytes: GazeData (basic gaze position)
-
AsyncIterator[GazeDataType]
–- 17 bytes: DualMonocularGazeData (left and right eye positions)
-
AsyncIterator[GazeDataType]
–- 65 bytes: EyestateGazeData (gaze with eye state)
-
AsyncIterator[GazeDataType]
–- 89 bytes: EyestateEyelidGazeData (gaze with eye state and eyelid info)
Source code in src/pupil_labs/realtime_api/streaming/gaze.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
receive_imu_data
async
¶
receive_imu_data(url: str, *args: Any, **kwargs: Any) -> AsyncIterator[IMUData]
Receive IMU data from a given RTSP URL.
Parameters:
-
url
(str
) –RTSP URL to connect to.
-
*args
(Any
, default:()
) –Additional arguments for the streamer.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments for the streamer.
Yields:
-
IMUData
(AsyncIterator[IMUData]
) –Parsed IMU data from the RTSP stream.
Source code in src/pupil_labs/realtime_api/streaming/imu.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
receive_raw_rtsp_data
async
¶
receive_raw_rtsp_data(url: str, *args: Any, **kwargs: Any) -> AsyncIterator[RTSPData]
Receive raw data from an RTSP stream.
This is a convenience function that creates an RTSPRawStreamer and yields timestamped data packets.
Parameters:
-
url
(str
) –RTSP URL to connect to.
-
*args
(Any
, default:()
) –Additional positional arguments passed to RTSPRawStreamer.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments passed to RTSPRawStreamer.
Yields:
-
RTSPData
(AsyncIterator[RTSPData]
) –Timestamped RTSP data packets.
Source code in src/pupil_labs/realtime_api/streaming/base.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
receive_video_frames
async
¶
receive_video_frames(url: str, *args: Any, **kwargs: Any) -> AsyncIterator[VideoFrame]
Receive video frames from an RTSP stream.
This is a convenience function that creates an RTSPVideoFrameStreamer and yields video frames.
Parameters:
-
url
(str
) –RTSP URL to connect to.
-
*args
(Any
, default:()
) –Additional positional arguments passed to RTSPVideoFrameStreamer.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments passed to RTSPVideoFrameStreamer.
Yields:
-
VideoFrame
(AsyncIterator[VideoFrame]
) –Parsed video frames.
Source code in src/pupil_labs/realtime_api/streaming/video.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|