simple
¶
Modules:
-
device
– -
discovery
– -
models
–
Classes:
-
Device
–Simple synchronous API for interacting with Pupil Labs devices.
-
MatchedGazeEyesSceneItem
–A matched triplet of scene video frame, eye video frame, and gaze data.
-
MatchedItem
–A matched pair of scene video frame and gaze data.
-
SimpleVideoFrame
–A simplified video frame representation.
Functions:
-
discover_devices
–Discover all available devices on the local network.
-
discover_one_device
–Discover and return the first device found on the local network.
Device
¶
Device(address: str, port: int, full_name: str | None = None, dns_name: str | None = None, start_streaming_by_default: bool = False, suppress_decoding_warnings: bool = True)
Bases: DeviceBase
Simple synchronous API for interacting with Pupil Labs devices.
This class provides a simplified, synchronous interface to Pupil Labs devices, wrapping the asynchronous API with a more user-friendly interface.
Important
Use [discover_devices][pupil_labs.realtime_api.simple.discovery. discover_devices] instead of initializing the class manually. See the simple_discovery_example example.
Parameters:
-
address
(str
) –IP address of the device.
-
port
(int
) –Port number of the device.
-
full_name
(str | None
, default:None
) –Full service discovery name.
-
dns_name
(str | None
, default:None
) –DNS name of the device.
-
start_streaming_by_default
(bool
, default:False
) –Whether to start streaming automatically.
-
suppress_decoding_warnings
(bool
, default:True
) –Whether to suppress decoding warnings.
Methods:
-
api_url
–Construct a full API URL for the given path.
-
close
–Close the device connection and stop all background threads.
-
convert_from
–Convert another device instance to this type.
-
estimate_time_offset
–Estimate the time offset between the host device and the client.
-
eye_events_sensor
–Get the eye events sensor.
-
from_discovered_device
–Create a device instance from discovery information.
-
gaze_sensor
–Get the gaze sensor.
-
get_calibration
–Get the current cameras calibration data.
-
get_errors
–Get a list of errors from the device.
-
get_template
–Get the template currently selected on the device.
-
get_template_data
–Get the template data entered on the device.
-
post_template_data
–Send the data to the currently selected template.
-
receive_eye_events
–Receive an eye event.
-
receive_eyes_video_frame
–Receive an eye camera video frame.
-
receive_gaze_datum
–Receive a gaze data point.
-
receive_imu_datum
–Receive an IMU data point.
-
receive_matched_scene_and_eyes_video_frames_and_gaze
–Receive a matched triplet of scene video frame, eye video frame, and gaze.
-
receive_matched_scene_video_frame_and_gaze
–Receive a matched pair of scene video frame and gaze data.
-
receive_scene_video_frame
–Receive a scene (world) video frame.
-
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.
-
start_stream_if_needed
–Start streaming if not already streaming.
-
streaming_start
–Start streaming data from the specified sensor.
-
streaming_stop
–Stop streaming data from the specified sensor.
-
world_sensor
–Get the world sensor.
Attributes:
-
battery_level_percent
(int
) –Get the battery level of the connected phone in percentage.
-
battery_state
(Literal['OK', 'LOW', 'CRITICAL']
) –Get the battery state of the connected phone.
-
is_currently_streaming
(bool
) –Check if data streaming is currently active.
-
memory_num_free_bytes
(int
) –Get the available memory of the connected phone in bytes.
-
memory_state
(Literal['OK', 'LOW', 'CRITICAL']
) –Get the memory state of the connected phone.
-
module_serial
(str | Literal['default'] | None
) –Returns
None
or"default"
if no glasses are connected -
phone_id
(str
) –Get the ID of the connected phone.
-
phone_ip
(str
) –Get the IP address of the connected phone.
-
phone_name
(str
) –Get the name of the connected phone.
-
serial_number_glasses
(str | Literal['default'] | None
) –Returns
None
or"default"
if no glasses are connected -
serial_number_scene_cam
(str | None
) –Returns
None
if no scene camera is connected -
version_glasses
(str | None
) –Get the version of the connected glasses.
Source code in src/pupil_labs/realtime_api/simple/device.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 |
|
battery_level_percent
property
¶
battery_level_percent: int
Get the battery level of the connected phone in percentage.
battery_state
property
¶
battery_state: Literal['OK', 'LOW', 'CRITICAL']
Get the battery state of the connected phone.
Possible values are "OK", "LOW", or "CRITICAL".
is_currently_streaming
property
¶
is_currently_streaming: bool
Check if data streaming is currently active.
Returns:
-
bool
(bool
) –True if streaming is active, False otherwise.
memory_num_free_bytes
property
¶
memory_num_free_bytes: int
Get the available memory of the connected phone in bytes.
memory_state
property
¶
memory_state: Literal['OK', 'LOW', 'CRITICAL']
Get the memory state of the connected phone.
Possible values are "OK", "LOW", or "CRITICAL".
module_serial
property
¶
Returns None
or "default"
if no glasses are connected
Info
Only available on Neon.
serial_number_glasses
property
¶
Returns None
or "default"
if no glasses are connected
Info
Only available on Pupil Invisible.
serial_number_scene_cam
property
¶
serial_number_scene_cam: str | None
Returns None
if no scene camera is connected
Info
Only available on Pupil Invisible.
version_glasses
property
¶
version_glasses: str | None
Get the version of the connected glasses.
Returns:
-
str
(str | None
) –1 -> Pupil Invisible, 2 -> Neon, or None -> No glasses connected.
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
¶
close() -> None
Close the device connection and stop all background threads.
This method should be called when the device is no longer needed to free up resources.
Source code in src/pupil_labs/realtime_api/simple/device.py
679 680 681 682 683 684 685 686 687 688 689 |
|
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 |
|
estimate_time_offset
¶
estimate_time_offset(number_of_measurements: int = 100, sleep_between_measurements_seconds: float | None = None) -> TimeEchoEstimates | None
Estimate the time offset between the host device and the client.
This uses the Time Echo protocol to estimate the clock offset between the device and the client.
Parameters:
-
number_of_measurements
(int
, default:100
) –Number of measurements to take.
-
sleep_between_measurements_seconds
(float | None
, default:None
) –Optional sleep time between
Returns:
-
TimeEchoEstimates
(TimeEchoEstimates | None
) –Statistics for roundtrip durations and time offsets, or None if estimation failed or device doesn't support the protocol.
See Also
:mod:pupil_labs.realtime_api.time_echo
for more details.
Source code in src/pupil_labs/realtime_api/simple/device.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
|
eye_events_sensor
¶
eye_events_sensor() -> Sensor | None
Get the eye events sensor.
Source code in src/pupil_labs/realtime_api/simple/device.py
215 216 217 |
|
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 |
|
gaze_sensor
¶
gaze_sensor() -> Sensor | None
Get the gaze sensor.
Source code in src/pupil_labs/realtime_api/simple/device.py
211 212 213 |
|
get_calibration
¶
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.
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/simple/device.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
get_errors
¶
Get a list of errors from the device.
Returns:
Source code in src/pupil_labs/realtime_api/simple/device.py
195 196 197 198 199 200 201 202 203 204 205 |
|
get_template
¶
get_template() -> Template
Get the template currently selected on the device.
Wraps pupil_labs.realtime_api.device.Device.get_template
Returns:
-
Template
(Template
) –The currently selected template.
Raises:
-
DeviceError
–If the template can't be fetched.
Source code in src/pupil_labs/realtime_api/simple/device.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
get_template_data
¶
get_template_data(template_format: TemplateDataFormat = 'simple') -> Any
Get the template data entered on the device.
Wraps pupil_labs.realtime_api.device.Device.get_template_data
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 result from the GET request.
Raises:
-
DeviceError
–If the template's data could not be fetched.
Source code in src/pupil_labs/realtime_api/simple/device.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
post_template_data
¶
post_template_data(template_data: dict[str, list[str]], template_format: TemplateDataFormat = 'simple') -> Any
Send the data to the currently selected template.
Wraps pupil_labs.realtime_api.device.Device.post_template_data
Parameters:
-
template_data
(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 from the POST request.
Raises:
-
DeviceError
–If the data can not be sent.
-
ValueError
–If invalid data type.
Source code in src/pupil_labs/realtime_api/simple/device.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
receive_eye_events
¶
receive_eye_events(timeout_seconds: float | None = None) -> FixationEventData | BlinkEventData | FixationOnsetEventData | None
Receive an eye event.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new eye event. If None, wait indefinitely.
Returns:
-
FixationEventData | BlinkEventData | FixationOnsetEventData | None
–FixationEventData | BlinkEventData | FixationOnsetEventData or None:
-
FixationEventData | BlinkEventData | FixationOnsetEventData | None
–The received eye event, or None if timeout was reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
receive_eyes_video_frame
¶
receive_eyes_video_frame(timeout_seconds: float | None = None) -> SimpleVideoFrame | None
Receive an eye camera video frame.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new frame. If None, wait indefinitely.
Returns:
-
SimpleVideoFrame | None
–SimpleVideoFrame or None: The received video frame, or None if timeout
-
SimpleVideoFrame | None
–was reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
receive_gaze_datum
¶
receive_gaze_datum(timeout_seconds: float | None = None) -> GazeDataType | None
Receive a gaze data point.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new gaze datum. If None, wait indefinitely.
Returns:
-
GazeDataType | None
–GazeDataType or None: The received gaze data, or None if timeout was
-
GazeDataType | None
–reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
receive_imu_datum
¶
Receive an IMU data point.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new IMU datum. If None, wait indefinitely.
Returns:
-
IMUData | None
–IMUData or None: The received IMU data, or None if timeout was reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
459 460 461 462 463 464 465 466 467 468 469 470 |
|
receive_matched_scene_and_eyes_video_frames_and_gaze
¶
receive_matched_scene_and_eyes_video_frames_and_gaze(timeout_seconds: float | None = None) -> MatchedGazeEyesSceneItem | None
Receive a matched triplet of scene video frame, eye video frame, and gaze.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a matched triplet. If None, wait indefinitely.
Returns:
-
MatchedGazeEyesSceneItem | None
–MatchedGazeEyesSceneItem or None: The matched triplet, or None if timeout
-
MatchedGazeEyesSceneItem | None
–was reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
receive_matched_scene_video_frame_and_gaze
¶
receive_matched_scene_video_frame_and_gaze(timeout_seconds: float | None = None) -> MatchedItem | None
Receive a matched pair of scene video frame and gaze data.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a matched pair. If None, wait indefinitely.
Returns:
-
MatchedItem | None
–MatchedItem or None: The matched pair, or None if timeout was reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|
receive_scene_video_frame
¶
receive_scene_video_frame(timeout_seconds: float | None = None) -> SimpleVideoFrame | None
Receive a scene (world) video frame.
Parameters:
-
timeout_seconds
(float | None
, default:None
) –Maximum time to wait for a new frame. If None, wait indefinitely.
Returns:
-
SimpleVideoFrame | None
–SimpleVideoFrame or None: The received video frame, or None if timeout was
-
SimpleVideoFrame | None
–reached.
Source code in src/pupil_labs/realtime_api/simple/device.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
recording_cancel
¶
recording_cancel() -> None
Cancel the current recording without saving it.
Wraps pupil_labs.realtime_api.device.Device.recording_cancel
Raises:
-
DeviceError
–If the recording could not be cancelled. Possible reasons
-
include
–- Recording not running
Source code in src/pupil_labs/realtime_api/simple/device.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
recording_start
¶
recording_start() -> str
Start a recording on the device.
Wraps pupil_labs.realtime_api.device.Device.recording_start
Returns:
-
str
(str
) –ID of the started recording.
Raises:
-
DeviceError
–If the 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/simple/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 |
|
recording_stop_and_save
¶
recording_stop_and_save() -> None
Stop and save the current recording.
Wraps pupil_labs.realtime_api.device.Device.recording_stop_and_save
Raises:
-
DeviceError
–If the recording could not be stopped. Possible reasons
-
include
–- Recording not running
- Template has required fields
Source code in src/pupil_labs/realtime_api/simple/device.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
send_event
¶
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/simple/device.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
start_stream_if_needed
¶
start_stream_if_needed(sensor: str) -> None
Start streaming if not already streaming.
Parameters:
-
sensor
(str
) –Sensor name to check.
Source code in src/pupil_labs/realtime_api/simple/device.py
562 563 564 565 566 567 568 569 570 571 |
|
streaming_start
¶
streaming_start(stream_name: str) -> None
Start streaming data from the specified sensor.
Parameters:
-
stream_name
(str
) –Name of the sensor to start streaming from. It can be one of
-
–
py:attr:
SensorName
values or None, which will start all streams.
Raises:
-
ValueError
–If the stream name is not recognized.
Source code in src/pupil_labs/realtime_api/simple/device.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|
streaming_stop
¶
streaming_stop(stream_name: str | None = None) -> None
Stop streaming data from the specified sensor.
Parameters:
-
stream_name
(str | None
, default:None
) –Name of the sensor to start streaming from. It can be one of
-
–
py:attr:
SensorName
values or None, which will stop all streams.
Raises:
-
ValueError
–If the stream name is not recognized.
Source code in src/pupil_labs/realtime_api/simple/device.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
MatchedGazeEyesSceneItem
¶
Bases: NamedTuple
A matched triplet of scene video frame, eye video frame, and gaze data.
This class represents scene and eye video frames along with gaze data that occurred at approximately the same time.
Attributes:
-
eyes
(SimpleVideoFrame
) –Eye camera video frame.
-
gaze
(GazeDataType
) –Corresponding gaze data.
-
scene
(SimpleVideoFrame
) –Scene video frame.
MatchedItem
¶
Bases: NamedTuple
A matched pair of scene video frame and gaze data.
This class represents a scene video frame and gaze data point that occurred at approximately the same time.
Note
The name MatchedItem is maintained for backward compatibility. It represents a matched pair of scene video frame and gaze data.
Attributes:
-
frame
(SimpleVideoFrame
) –Scene video frame.
-
gaze
(GazeDataType
) –Corresponding gaze data.
SimpleVideoFrame
¶
Bases: NamedTuple
A simplified video frame representation.
This class provides a simplified representation of a video frame with BGR pixel data and timestamp information.
Attributes:
-
bgr_pixels
(BGRBuffer
) –BGR pixel data as a NumPy array.
-
timestamp_unix_seconds
(float
) –Timestamp in seconds since Unix epoch.
discover_devices
¶
Discover all available devices on the local network.
This function searches for devices on the local network for the specified duration and returns all discovered devices.
Parameters:
-
search_duration_seconds
(float
) –How long to search for devices in seconds.
Returns:
Example
# Discover devices for 5 seconds
devices = discover_devices(5.0)
for device in devices:
print(f"Found device: {device.phone_name}")
See Also
The asynchronous equivalent
:func:pupil_labs.realtime_api.discovery.discover_devices
Source code in src/pupil_labs/realtime_api/simple/discovery.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
discover_one_device
¶
Discover and return the first device found on the local network.
This function searches for devices on the local network and returns the first discovered device, or None if no device is found within the specified maximum search duration.
Parameters:
-
max_search_duration_seconds
(float | None
, default:10.0
) –Maximum time to search for a device in seconds. If None, search indefinitely. Default is 10.0 seconds.
Returns:
-
Device | None
–Device or None: The first discovered device, or None if no device was found
-
Device | None
–within the specified time limit.
Example
# Try to find a device within 5 seconds
device = discover_one_device(5.0)
if device:
print(f"Found device: {device.phone_name}")
else:
print("No device found")
See Also
The asynchronous equivalent
:func:pupil_labs.realtime_api.discovery.Network.wait_for_new_device
Source code in src/pupil_labs/realtime_api/simple/discovery.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|