esppy.windows.Subscriber¶
-
class
esppy.windows.
Subscriber
(window, mode='updating', pagesize=50, filter=None, sort=None, format='xml', separator=None, interval=None, schema=False, on_event=None, on_message=None, on_error=None, on_close=None, on_open=None, precision=6)¶ Bases:
object
Create a subscriber for the given window
- Parameters
- windowWindow
The window object to create the subscriber for
- modestring, optional
The mode of subscriber: ‘updating’ or ‘streaming’
- pagesizeint, optional
The maximum number of events in a page
- filterstring, optional
Functional filter to subset events
- sortstring, optional
Sort order for the events (updating mode only)
- formatstring, optional
The format of the received data: ‘xml’, ‘json’, ‘csv’, ‘properties’
- separatorstring, optional
The separator to use between events in the ‘properties’ format
- intervalint, optional
Interval between event sends in milliseconds
- precisionint, optional
The floating point precision
- schemabool, optional
Should the schema be sent with the first event?
- on_eventcallable, optional
The object to call for events. The argument to this object will be a DataFrame of the events that occurred.
- on_messagecallable, optional
The object to call for each websocket message
- on_errorcallable, optional
The object to call for each websocket error
- on_closecallable, optional
The object to call when the websocket is opened
- on_opencallable, optional
The object to call when the websocket is closed
- Returns
Examples
Create event callback;
event
is a DataFrame>>> def on_event(event): ... print(event.columns)
Create the subscriber instance
>>> sub = Subscriber(window, on_event=on_event)
Start event processing (runs a thread in the background)
>>> sub.start()
Stop event processing (stops background thread)
>>> sub.stop()
- Attributes
- callbacksdict
The dictionary of callback functions
filter
stringFunctional filter to subset events
- formatstring, optional
The format of the received data: ‘xml’, ‘json’, ‘csv’, ‘properties’
interval
intInterval between event sends in milliseconds
is_active
boolIs the web socket active?
mode
stringThe mode of the subscriber: ‘updating’ or ‘streaming’
pagesize
intThe maximum number of events in a page
separator
string, optionalSeparator to use between events in the ‘properties’ format
- schemabool
Should the schema be sent with the first event?
sort
stringSort order for the events (updating mode only)
- window_schemaSchema
The schema of the window being subscribed to
- window_urlstring
The subscriber URL of the window
-
__init__
(self, window, mode='updating', pagesize=50, filter=None, sort=None, format='xml', separator=None, interval=None, schema=False, on_event=None, on_message=None, on_error=None, on_close=None, on_open=None, precision=6)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(self, window[, mode, pagesize, …])Initialize self.
close
(self)Stop processing events and close the web socket
start
(self)Initialize the web socket and start it in its own thread
stop
(self)Stop processing events and close the web socket
Attributes
filter
Functional filter to subset events
interval
Interval between event sends in milliseconds
is_active
Is the web socket active?
mode
The mode of the subscriber: ‘updating’ or ‘streaming’
pagesize
The maximum number of events in a page
separator
Separator to use between events in the ‘properties’ format
sort
Sort order for the events (updating mode only)
url
Return the URL of the subscriber