read_history_events
If the server logs event history (HistoryRead Events), the client can retrieve historical events by time range.
- To subscribe to real-time events, please use Event Subscription.
- Please use the following historical variable data: read_history (Raw) / read_history_processed.
Signature
def read_history_events(self,
node_id: str,
start_utc: datetime,
end_utc: datetime,
max_events: int = 0) -> List[HistoryEventArgs]: ...
node_id Typically, this is a ( i=2253 Server node) or a custom EventNotifier node.max_events=0 Indicates an unlimited number of entries; an empty node_id string results in a throw ValueError.
HistoryEventArgs
@dataclass
class HistoryEventArgs:
severity: int = 0
message: Optional[str] = None
source_name: Optional[str] = None
time: Optional[datetime] = None
event_type: Optional[str] = None
The field semantics are the same as EventArrivedEventArgs, but its lifecycle corresponds to the lifetime of the returned list (since it is managed, it does not need to be disposed of).
4 standard SelectClauses are built in: Severity / Message / SourceName / Time.
Usage
import datetime as dt
now = dt.datetime.now(dt.timezone.utc)
events = ua.read_history_events(
"i=2253",
start_utc=now - dt.timedelta(days=1),
end_utc=now)
for e in events:
print(f"[{e.severity}] {e.source_name}: {e.message} @ {e.time}")
Custom EventFilter
read_history_events does not accept custom SelectClauses / EventFilter parameters; the 4 built-in fields are always used. If you want to filter by EventType / Severity, you'll have to sort the results yourself after retrieving them.
The entry point EventFilter for custom is EventSubscription.subscribe(node_id, event_filter=...) (advanced usage; see Event Subscription), applies only to real-time event subscriptions; it does not apply to historical reads.
Server Requirements
- Must support HistoryRead Events (ServerCapabilities flag on the server side)
- The event source node must have bit 1 of the EventNotifier Attribute (12) set (HistoryRead)
Relationship to Real-Time Event Subscriptions
| API | What to bring |
|---|---|
| subscribe_events(...) | Real-time Events (Occurring During the Subscription Period) |
| read_history_events(...) | Historical Events (Archived on the Server) |
Typical setup: read_history_events Run it for 24 hours at startup, then subscribe_events switch to real-time operation.