Simple vs. Async API¶
The module provides two conceptionally different APIs:
-
The
asyncinterface is using Python's asyncio in order to implement non-blocking asynchronous communication. It provides composable components for each feature of the Network API. This means that you need to select and combine the functionality for your own needs, e.g. stream_video_with_overlayed_gaze example. Theasyncfunctionality is implemented in the top-levelpupil_labs.realtime_apinamespace. -
The
simpleinterface wraps around theasyncone, sacrificing flexibility for the sake of ease of use. It tries to anticipate and provide a solution for the most common use cases. Note, allsimpleAPI functionality can be found in thepupil_labs.realtime_api.simplenamespace.
Do not mix async and simple components!
The async and simple components are not compatible with each other! Do not mix
them!
Device Classes¶
There are three different Device classes that one needs to differentiate:
-
pupil_labs.realtime_api.simple.device.DeviceEasy-to-use class that auto-connects to the Companion device on__init__to request the current status and to keep it up-to-date via the Websocket API. The phone's state is mirrored and cached in the corresponding attributes. Accessing the attributes is instant and does not need to perform a request to the phone. The class initiates streaming on demand (pupil_labs.realtime_api.simple.Device.streaming_start) or when needed (any of thesimple.Device.receive_*methods being called). Can be initialised with an explicit IP address and port number. Also, returned by thepupil_labs.realtime_api.simple.discover_*functions. -
pupil_labs.realtime_api.models.DiscoveredDeviceInfoMeta-information about discovered devices, e.g. IP address, port number, etc. Not able to initiate any connections on its own. Used to configure the following class: -
pupil_labs.realtime_api.device.DeviceDoes not connect to the Companion device on__init__- only explicitly on calls like pupil_labs.realtime_api.device.Device.get_status. Subscription to theWebsocket API, streaming, andclock offset estimationare implemented in separate components.
When to use which API?¶
The simple API is the best choice for most users. It is easy to use and provides a high-level interface for common tasks. The async API is more flexible and powerful, but it requires a deeper understanding of asynchronous programming and the underlying components. If you need to implement custom functionality or have specific performance requirements, the async API may be the better choice.