Skip to main content

read_history (Raw)

def read_history(self,
node_id: str,
start_utc: datetime,
end_utc: datetime,
max_values: int = 0) -> List[OpcUaDataValue]: ...

The most commonly used historical read, which returns all raw data points within the specified [start_utc, end_utc] interval.

Preliminary / Supporting

Parameters​

ParametersDefaultNote
node_id—Objective NodeId
start_utc—Start of range (UTC datetime)
end_utc—Range Stop (UTC datetime)
max_values0 (No limit)Maximum number of results per query

Usage​

import datetime as dt

dvs = ua.read_history(
"ns=2;s=Temperature",
start_utc=dt.datetime.now(dt.timezone.utc) - dt.timedelta(hours=1),
end_utc=dt.datetime.now(dt.timezone.utc),
max_values=1000)

for dv in dvs:
with dv:
print(f"{dv.source_timestamp.isoformat()}: {dv.value} ({dv.status.name})")

Exception​

Thrown when the server returns a value other than "Good" OpcUaException; the status code is taken from the server's return value ( ex.status_code on ). Common examples:

ExceptionMeaning
OpcUaException(StatusCode.BadHistoryOperationUnsupported)There is no Historian on the server
OpcUaException(StatusCode.BadUserAccessDenied)The user does not have permission to view the history.
OpcUaException(StatusCode.BadNotReadable)Node is not readable
OpcUaException(StatusCode.BadCommunicationError)Network Outage

Status codes outside the enumeration are treated as StatusCode.Bad (the original codes within the exception are retained).

When dealing with large amounts of data​

Retrieves RPC all points within the range in a single operation. Currently, there is no mechanism for pagination ContinuationPoint, so there is no "page navigation" step; the number of rows returned max_values is truncated. For high-frequency data, please use read_history_processed Aggregation or business-side slicing.

Performance and Best Practices​

  • High-frequency data (1000 Hz+) pulled for one day = 86 million+ points → Must use a max_values limit or switch to read_history_processed Aggregation

  • OpcUaDataValue Every element in the list must be disposed of. Recommended:

    for dv in dvs:
    with dv:
    # Release after use
    ...
  • All timestamps must be consistent UTC; do not use local time.

Next Step​