IMD SolutionComputing LibraryShop main store

How-to

Reading Ignition historian data from MATLAB or Python

Edge computing and IIoT Published 6 min read

Short answer

Put a REST endpoint on the Ignition gateway with the Web Dev module: it runs system.tag.queryHistory for the requester and returns JSON or CSV, so MATLAB or Python parses a defined recordset and never touches historian storage tables. Direct SQL against the documented tables is the fallback; an SDK module is the heavyweight path. One contract to define: tag paths, time bounds, alignment basis, output format.

On this page
  1. Why the client cannot call the history function
  2. Three ways across the boundary
  3. Define the request contract
  4. Build the endpoint in the Web Dev module
  5. The client side is one HTTP request
  6. Verifying a 23-day, two-tag request on a one-hour basis
  7. When the response does not match
  8. Keep the endpoint inside a controlled boundary
  9. Questions asked

Ignition's history function runs inside the gateway, so MATLAB and Python cannot call it as a library — but a REST endpoint built with the Web Dev module gives them the same result. The endpoint receives tag paths and a time range, runs system.tag.queryHistory, and returns JSON or CSV; the external client makes one HTTP request and never learns which storage tables hold the interval or how each tag's logging times line up. Direct SQL against the documented historian tables is the fallback for teams that want to own that logic, and a module built with the Ignition SDK is the heavyweight path. What follows is the request contract, the build steps, and a verification pass with real numbers.

Why the client cannot call the history function #

system.tag.queryHistory executes in the gateway's scripting environment. An external MATLAB or cPython process has no handle into that environment, so there is no local-call path from an analysis script into the historian. When a chart inside Ignition shows data for the same tags and range, the historian is doing its job and the only thing missing is an interface: this is an access-boundary problem, not a logging fault.

If the same query returns nothing inside Ignition, stop building endpoints and fix the logging side first. One documented pattern of that kind of fault is the historian logging memory tags but not OPC tag changes.

Three ways across the boundary #

Approach How it works Choose it when What you carry
Web Dev REST endpoint A Python resource on the gateway's web server takes tags plus a time range, runs the history query, returns JSON or CSV MATLAB or Python analysts need repeatable, interactive access One page of gateway script and a response contract you define
Direct SQL The client queries the historian's database itself A one-off investigation by someone who already knows the schema Table selection across the time range, per-tag timestamp alignment, and breakage when the layout changes
Ignition SDK module A third-party module built on the SDK You are building a maintained, product-grade integration A Java development project, not a ready-made interface
Gateway script export Scripts write CSV or Excel files Occasional extracts Tag names and start and end dates typed in by hand each time

For repeatable analysis from MATLAB or Python, build the endpoint. Direct SQL is the fallback for a one-off dig by someone who accepts the schema work; the SDK is for shipping a product, not for reading tags into a notebook.

Define the request contract #

Fix four elements before writing any code, because every later mismatch traces back to one of them:

  • Tag identifiers. Exact tag paths as the historian knows them, not display names.
  • Time bounds. An explicit start and end, in one agreed format and time zone on both sides of the request.
  • Alignment basis. Tags log at their own times, so rows across multiple tags line up only if the request asks for a common basis. Never assume equal timestamps across tags that log independently.
  • Output format. JSON or CSV, chosen per request.

Validate on the gateway before querying: reject missing tags, malformed bounds, and unsupported formats with an explicit error rather than an empty success. Keep column names and the timestamp representation stable so client code survives small endpoint changes.

Build the endpoint in the Web Dev module #

  1. Install and license the Web Dev module on the gateway. It is the module documented for building RESTful web service APIs on the Ignition server; confirm it on the gateway's module page before any client depends on it.
  2. Create a Python resource for the history path and implement its doGET handler — read-only history queries belong in a GET.
  3. Read the tags, start, end, basis, and format from the request and validate all five. Return an error status for anything unsupported instead of an empty 200.
  4. Call system.tag.queryHistory from that handler with the selected tag paths and bounds, using the parameter set documented for the installed Ignition release.
  5. Serialize the returned recordset to JSON or CSV with stable column names and one timestamp format.
  6. Serve an approved tag list rather than the whole tag tree — the same approval discipline as exposing only approved Ignition tags to an external historian.

The client side is one HTTP request #

import requests  # third-party HTTP library

historian_url = "http://gateway-host/api/history"  # illustrative endpoint path
query = {
    "tags": ["TagA", "TagB"],
    "start": "2019-02-02 00:00:00",
    "end": "2019-02-25 00:00:00",
    "basis": "1h",
    "format": "json",
}
response = requests.get(historian_url, params=query, timeout=30)
rows = response.json()  # list of rows: {"t": ..., "TagA": ..., "TagB": ...}

Every key in query is this article's illustrative contract, not an Ignition parameter name. MATLAB reaches the same URL with its built-in HTTP client and JSON decoding; nothing in the endpoint is Python-specific.

Verifying a 23-day, two-tag request on a one-hour basis #

Inputs:

  • Tags: TagA and TagB — the two series from the example request that motivated this article.
  • Bounds: 2019-02-02 00:00:00 to 2019-02-25 00:00:00 — that request's date range.
  • Basis: one row per hour — the alignment basis the contract above defines.
  • Format: JSON.

Rule in words: the expected row count equals the elapsed hours divided by the basis interval in hours, and each row carries one timestamp plus one value per tag.

Arithmetic:

2019-02-25 − 2019-02-02 = 23 days 23 days × 24 h/day = 552 h 552 h ÷ 1 h/row = 552 rows 552 rows × 3 fields/row (1 timestamp + 2 tag values) = 1656 fields

Result: the client must parse 552 rows of 3 fields. The test that proves it belongs in the client:

assert len(rows) == 552

Decision: exactly 552 rows and the contract held — the response honored the requested basis. Any other count means the endpoint returned the tags' raw logging timestamps instead of the hourly basis, because tags that log on change store rows at their own times; fix the endpoint's basis handling, not the client. A correct count with wrong values means the bounds were interpreted in a different time zone; fix bound parsing on one side. At two tags over 23 days this is a five-second check, so keep it in the client permanently.

When the response does not match #

  • Zero rows. Check tag paths and bounds first, then confirm those tags have history recorded in that interval by running the same range inside Ignition.
  • Fewer rows than expected. The basis was not applied — run the count check above before touching anything else.
  • Values differ from an Ignition chart. Compare the history options carried in the request against the chart's query; interpolation choices move numbers.
  • Direct SQL disagrees with the endpoint. Suspect the SQL — its table selection for the time range and its timestamp handling — before the endpoint, and know where the Ignition Edge tag historian writes its data before querying storage directly.

Keep the endpoint inside a controlled boundary #

This endpoint reads plant history without authentication unless you build it in, so treat it as an OT exposure: leave it on the control network, require authentication at the endpoint or in front of it, and use TLS wherever the path crosses a shared network. When analysts must reach it from outside, put a reverse proxy in front of the Web Dev module and terminate access control there.

Questions asked

Is direct SQL against the historian tables documented anywhere?

Yes. The table layouts appear in the Ignition user manual's database table reference, down to a metadata table where each row represents one version of a tag's historical configuration. The documentation describes the storage, not a query service: table selection across a time range and alignment of per-tag timestamps stay in your code, and a layout change on upgrade breaks those queries while endpoint clients keep working because they go through the history function.

Should the endpoint return JSON or CSV?

JSON, by default. Both Python and MATLAB decode JSON natively, so the recordset arrives as structured rows instead of a string to parse, and a format parameter can still serve users who want files. CSV earns its keep when the workflow is file-oriented: spreadsheets, archives, or analysis tools that ingest files directly rather than making requests.

How do analysts pick tags without typing paths by hand?

Add a second endpoint that returns tag names and paths as JSON. The client displays that list, the user selects tags and a date range, and the selection is passed to the query endpoint. This keeps discovery separate from the query itself and stops mistyped tag paths before they reach the historian.

The request returns no rows - is the historian broken?

Usually not. Query the same tag paths and time range inside Ignition first: if a chart there shows data, the historian is logging and the fault is in the request - tag path spelling, bounds the gateway read in a different time zone, or validation that silently rejected an input. Only if Ignition itself returns nothing for the same range is it a logging fault.

Keep reading

  • How-to

    Expose only approved Ignition tags to an external historian

    No — on Ignition 8.1 an authenticated OPC UA client browses everything, and the gateway will not run a second UA server. Republish only the approved tags through a separate server such as Node-RED with the Ignition Node-RED module, firewall Ignition's own endpoint, or move to 8.3 role-based access.

    Edge computing and IIoT

  • Troubleshooting

    Read Proficy Historian OPC-HDA tags into Ignition

    Create the Proficy historical connection through the OPC COM module's documented OPC-HDA workflow, not the new OPC Server connection dialog. Charts get their data from interval reads; values usable as Designer tags need a runScript bridge into a shared script built on system.opchda.readRaw. Enabling tag history on bridged tags stores new values only — the existing Proficy archive is not migrated.

    Edge computing and IIoT

  • How-to

    Bridge Ignition tag history after a tag path change

    Yes — the data is intact, and two database repairs bridge it onto the current path. Repoint the old sqlth_te entry at the current tag path and set its retired timestamp at the cutover, or rewrite the old tagid to the new one in every sqlt_data_x_xxxx partition and pull the new entry's created timestamp back. Disable the history provider first, because tag metadata is cached in RAM.

    Edge computing and IIoT