Simple vs. Async API¶
The module provides two conceptionally different APIs:
The
async
interface 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. Scene Camera Video With Overlayed Gaze. Theasync
functionality is implemented in the top-level pupil_labs.realtime_api namespace.The
simple
interface wraps around theasync
one, sacrificing flexibility for the sake of ease of use. It tries to anticipate and provide a solution for the most common use cases. Note, allsimple
API functionality can be found in thepupil_labs.realtime_api.simple
namespace.
Caution
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:
- Easy-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. - Meta-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:
- Does not connect to the Companion device on
__init__
- only explicitly on calls likepupil_labs.realtime_api.device.Device.get_status()
. Subscription to theWebsocket API
, streaming, andclock offset estimation
are implemented in separate components.