Skip to content
cB-SigmaPublic

About

AVEVA PI Web API client in pure Go: points, Asset Framework, every stream and stream-set read, writes with partial failures, stream updates, batch, WebID 2.0; Basic, Bearer and Kerberos logins

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

piwebapi

A client for the AVEVA PI Web API (formerly OSIsoft) in pure Go, with Kerberos login that works from settings alone; not affiliated with AVEVA.

Go Reference test Licence: Apache-2.0 Go

It reads and writes time-series data in a PI System through the PI Web API: points and Asset Framework objects (servers, databases, elements, attributes, event frames), every stream read (value, end, recorded with paging and backfill, interpolated, at times, plot, summary), value and values updates with partial failures reported per item, stream sets of many streams in one call, stream updates (polling by marker), batch requests, and WebID 2.0 helpers. Logins are Basic, Bearer, or Kerberos (HTTP Negotiate) through gokrb5, configured from krb5.conf text and a keytab or password, with nothing read from disk. The root package uses the Go standard library only; no cgo. It was written for SigmaM2M, a oneM2M platform, whose historian adapter is built on it.

Why it exists: the Go PI Web API clients found (gowebapi and its forks, generated from a 2018 API description) are unmaintained and have no Kerberos login, which many PI Web API servers require.

Support matrix

Every PI Web API action this module calls, by controller. "Not yet" rows say why. Other GET actions can be made with Client.Get, and any other action with Client.Do (which sends the CSRF header for writes).

Controller and action Method Status
Home, System: system, system/userinfo (login and delegation check), system/versions, system/status System, UserInfo, Versions, Status yes
DataServer: list, by name, by path, by WebId DataServers, DataServerByName, DataServerByPath, DataServer yes
DataServer: points by name filter, paged by startIndex and maxCount Points, PointPages yes
Point: by path, by WebId, several by path (points/multiple), point attributes PointByPath, Point, PointsByPath, PointAttributes yes
AssetServer: list, by name, by path, by WebId, its databases AssetServers, AssetServerByName, AssetServerByPath, AssetServer, AssetDatabases yes
AssetDatabase: by path, by WebId, elements (filters, full hierarchy, paging, sort), event frames AssetDatabaseByPath, AssetDatabase, Elements, EventFrames yes
Element: by path, by WebId, several by path, child elements, attributes, event frames that reference it ElementByPath, Element, ElementsByPath, ChildElements, Attributes, ElementEventFrames yes
Attribute: by path, by WebId, several by path, child attributes, value (GET; PUT for static values) AttributeByPath, Attribute, AttributesByPath, ChildAttributes, AttributeValue, SetAttributeValue yes
EventFrame: search (every search mode, time range, name, referenced element, template, category, severity, acknowledgement, paging), by path, by WebId, children, attributes EventFrames, EventFrameByPath, EventFrame, ChildEventFrames, EventFrameAttributes yes
Stream: value (snapshot or at a time), end Value, End yes
Stream: recorded (boundary type, maxCount, filter expression, filtered values), with backfill paging Recorded, RecordedWith, RecordedPages yes
Stream: interpolated (interval as PI time span, sync time), interpolated at times, plot Interpolated, InterpolatedWith, InterpolatedAtTimes, Plot yes
Stream: recorded at time and at times (every retrieval mode) RecordedAtTime, RecordedAtTimes yes
Stream: summary (every summary type, time- or event-weighted, per duration, sampling) Summary yes
Stream: update value, update values (update and buffer options; 202, 204, 207 with per-item substatus) UpdateValue, UpdateValues yes
Stream updates: register, read by marker; for one stream and for a stream set RegisterUpdates, Updates, RegisterStreamSetUpdates, StreamSetUpdates yes
StreamSet, ad hoc (webId= list) and of an element or event frame (streamsets/{webId}): value, end, recorded, interpolated, interpolated at times, plot, summary, recorded at time and times; per-stream failures (WebException) StreamSet* with Streams yes
StreamSet: update value and values, ad hoc (207 per stream and per value) StreamSetUpdateValue, StreamSetUpdateValues yes
StreamSet: update value and values of an element (POST streamsets/{webId}/...) Not yet: the ad hoc writes take the attributes' WebIds and do the same
Batch: requests with parent IDs, JSONPath parameters, request templates; 207 Batch, BatchGet, BatchPost, BatchResponse yes
Common parameters: selectedFields, webIdType, timeZone, desiredUnits, any other through Extra Common yes
WebID 2.0: read a WebId's type, marker, owner and path; build path-only WebIds ParseWebID, PathWebID, PointWebID, AttributeWebID yes (header and path-only payloads; full WebIds' GUIDs are not decoded)
Values: numbers, text, booleans, digital and system states; Good, Questionable, Substituted, Annotated, per-value Errors Value.Decode, State, Float, IsGood yes
Errors: {"Errors": [...]} bodies, 401/403 (AuthError, with the offered schemes and an NTLM hint), 404 (IsNotFound), 408/429/5xx (Temporary, RetryAfter), timeouts through the context Error, AuthError, PartialError yes
Logins: Basic, Bearer, Kerberos with a password or keytab (negotiate) Basic, Bearer, negotiate.Service yes
CSRF defence: X-Requested-With on POST, PUT, PATCH, DELETE (batch included) Client.RequestedWith yes
Channels (streams/{webId}/channel, streamsets/channel) Not yet: they are WebSockets; the standard library has no WebSocket client and this module keeps its dependencies to gokrb5. Stream updates give the same changes by polling
Calculation (calculation/...), indexed Search (search/query), elements/search and attribute searches Not yet: not needed by the module's first user; reachable with Get
Configuration changes: create, update or delete points, elements, attributes, event frames, databases; security entries; tables; enumeration sets; analyses; notifications; OMF Not yet: this module reads and writes data, not configuration; reachable with Do
NTLM No: it is not a login method the PI Web API documents. When a Windows host answers Negotiate with NTLM (no service principal for the name asked), AuthError.NTLM says so
Paging links (Links.Next) Not read: list reads page by startIndex and maxCount; recorded reads have no next link and page by timestamp

Limits worth knowing:

  • Recorded, Interpolated and RecordedPages keep their v0 signatures (absolute times; the interval in whole seconds). The ...With forms take PI time expressions and time spans as text.
  • RecordedPages resumes at the last timestamp of a full page and drops the values already read there. When page or more values share one instant, the values beyond the page at that instant are skipped.
  • Times are sent in UTC with seven fractional digits (100 ns); a time without a zone would be read in the server's own zone.
  • The PI Web API caps one call's items (MaxReturnedItemsPerCall); a read above the cap fails with 400. Page or narrow such reads.

Install

go get github.com/cB-Sigma/piwebapi@latest

Requires Go 1.26 or later.

Quick start

import (
	"github.com/cB-Sigma/piwebapi"
	"github.com/cB-Sigma/piwebapi/negotiate"
)

k, err := negotiate.New(negotiate.Config{Realm: "PLANT.EXAMPLE", KDCs: []string{"dc1.plant.example"},
	Username: "svc-reader", Password: password})
c := piwebapi.New("https://pi.plant.example/piwebapi", nil, k.For(negotiate.SPNFor("https://pi.plant.example")))

pt, err := c.PointByPath(ctx, `\\PISRV01\BLR1.STEAM.TEMP`)
err = c.RecordedPages(ctx, pt.WebID, since, time.Now(), 1000, func(v piwebapi.Values) error {
	for _, x := range v.Items {
		val, quality := x.Decode() // quality: "", or bad, questionable, substituted, system
		_ = val
	}
	return nil
})

// Many attributes in one call, and a write.
el, err := c.ElementByPath(ctx, `\\PIAF01\Plant\Area1\Boiler1`)
vals, err := c.StreamSetValue(ctx, piwebapi.Streams{Of: el.WebID}, piwebapi.ValueOptions{})
err = c.UpdateValue(ctx, pt.WebID, piwebapi.TimedValue{Value: 181.5}, piwebapi.UpdateOptions{})

Example in example_test.go shows the Kerberos flow (it needs a server, so it is not run); ExampleValue_Decode and ExamplePointWebID run. piwebapi-sim runs the same calls against a simulated PI Web API and a test KDC.

Documentation

API reference: https://pkg.go.dev/github.com/cB-Sigma/piwebapi

Package What it does
piwebapi (module root) Client (Get, Do, URL, and the methods in the matrix above), the value, object and option types, Time, Tick, Authorizer with Basic and Bearer, ErrAuth, AuthError, Error, PartialError, IsNotFound, WebID 2.0 helpers. Standard library only
negotiate Kerberos V5 login and SPNEGO Authorization: Negotiate headers through gokrb5: krb5.conf text parsed in memory, keytab bytes or base64, AES and TCP by default, ErrLogin for a refused login, Problem naming the bad setting, re-login when a session fails; hooks CheckKDC (egress rules) and WeakEtype (crypto policy); SPNFor, Client.For(spn)

Changes per version are in CHANGELOG.md.

Testing

go test -race ./...

The tests here check the requests the client sends for every action (method, path, query, headers, body) and how it reads canned answers: 207 partial failures, batch responses, per-stream exceptions, refusals, server errors with Retry-After, timeouts, WebIds, paging. The tests that drive a PI Web API, against the simulator and the test KDC, are in piwebapi-sim.

Interop tested against

  • Not yet: a real PI Web API. None was available; the request shapes come from AVEVA's public PI Web API reference and from the public client generated from its 2018 API description (OSIsoft's PI-Web-API-Client-Python, read for parameter and field names only). Stream updates and the Annotated flag are newer than that client and come from the reference alone.
  • The simulator in piwebapi-sim and this client have the same author, so their agreement is not independent evidence.
  • Kerberos: the login and SPNEGO tokens are gokrb5's. They are tested against piwebapi-sim's test KDC (written from RFC 4120 on gokrb5's message types) and a service that checks tickets with gokrb5's acceptor; not yet against Active Directory or an IIS-hosted PI Web API.

Related repositories

  • piwebapi-sim: a simulated PI Web API and a test Kerberos KDC, as Go packages and a command.

Status

v0.x: the API may change before v1.

Contributing

See CONTRIBUTING.md.

Security

See SECURITY.md to report a vulnerability privately.

Licence

Apache-2.0 (see LICENSE and NOTICE). Copyright 2026 Abhinav Gautam. AVEVA, OSIsoft, PI System and PI Web API are trademarks of their owners; the names are used only to say which product this module talks to.

About

AVEVA PI Web API client in pure Go: points, Asset Framework, every stream and stream-set read, writes with partial failures, stream updates, batch, WebID 2.0; Basic, Bearer and Kerberos logins

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages