Skip to main content

Delete Historical Data

Regulatory Requirements

Data deletion is a highly sensitive operation; most industry regulations (GMP / FDA / ISO) require that data be "never deleted" or that "deletion must be auditable." Server-side implementations may include additional safeguards.

delete_history_range​

Delete all data points within the specified time range.

def delete_history_range(self,
node_id: str,
start_utc: datetime,
end_utc: datetime,
delete_modified_too: bool = False) -> StatusCode: ...
ParametersNote
node_idTarget historical point NodeId; throws an empty string ValueError
start_utcStart Time (UTC, inclusive)
end_utcEnd Time (UTC, inclusive)
delete_modified_tooTrue = Delete the modified history; False = Delete the raw history (the two types of history are deleted separately; they are not all deleted at once)

Returns an enumeration StatusCode value; readable st.name (e.g., Good). Method-levelNo cancellation / timeout parameters。

import datetime as dt

now = dt.datetime.now(dt.timezone.utc)
st = ua.delete_history_range(
"ns=2;s=Temperature",
start_utc=now - dt.timedelta(days=30),
end_utc=now - dt.timedelta(days=7))
print(st.name)

Delete at a specific time (Go update_history)​

OPC UA treats "delete by timestamp" as a HistoryUpdate of type HistoryUpdateType.REMOVE:

from darra_opcua import HistoryUpdateType

# REMOVE Mode: The value of OpcUaDataValue each entry in the `values` list source_timestamp determines which points are deleted.
results = ua.update_history("ns=2;s=Temperature", HistoryUpdateType.REMOVE, dv_list)

For more information, see update_history.

Delete Event History​

Service for EventId Deleting Event History (HistoryUpdate DeleteEventDetails) Currently SDK Not displayed, There are no corresponding entry points in Python or C#. Event history is currently read-only; it cannot be deleted (for reading, see read_history_events)。

Regulatory Constraints​

  • Never Delete (Only allow "obsolete" tags)
  • Deletions must be logged for auditing purposes (who deleted it, when, and why).

The server-side implementation may include additional safeguards. The client may receive BadUserAccessDenied.

Calling Thread​

delete_history_range is a synchronous method that occupies the calling thread until the RPC returns (there are no cancellation / timeout parameters at method level, and a single call's RPC duration is bounded by the session's request_timeout_ms). On a UI thread this call blocks until it returns; run long operations on a background thread instead:

import datetime as dt
import threading

now = dt.datetime.now(dt.timezone.utc)
start = now - dt.timedelta(days=30)
end = now - dt.timedelta(days=7)

def do_delete():
ua.delete_history_range("ns=2;s=Temperature", start, end)

threading.Thread(target=do_delete, daemon=True).start()

Next Step​