Python examples
Manage Calculations
create a single calculation this code creates a calculation ( my swagger ) this is the same endpoint used to create a measurement however, for calculations there are some more settings to consider databaseuuid retrieve by manage time series databases docid\ yhpic w9fthy09n103qcd collectoruuid retrieve by manage collectors docid\ pc5 4ldexbiryshmxcdph and extracting the uuid of the calculation collector datatype e g number, boolean, string name e g mycalculation status e g active, paused settings type e g sampled, raw or simulated inputs list of input measurements or calculations to retrieve from manage measurements docid\ ocuypopzcouihwwzc vj7 (only when calculation type is raw or sampled ) type measurement or calculation uuid the uuid of the measurement or calculation aggregation the aggregation to use per calculation inteval e g last, first, mean, (only when calculation type is sampled ) script the calculation script in which newline characters should be replaced with \n and tabs with \t interval the calculation interval at which the calculation script is evaluated e g 5s (only when calculation type is sampled or simulated) intervaloffset the offset in seconds on the calculation interval e g 0s (only when calculation type is sampled or simulated) evaluateinsufficientdata to evaluate the calculation script if one of the inputs has no data (insufficient data) e g true or false (only when calculation type is sampled ) attributes config uom the unit of measure e g m limithi the upper limit of the calculation limitlo the lower limit of the calculation valuemax the maximum value to be shown on the y axis of a graph in grafana using the factry historian datasource valuemin the minimum value to be shown on the y axis of a graph in grafana using the factry historian datasource post post https //historian mycompany com 18000/api/measurements def create calculation( database uuid optional\[str], collector uuid str, datatype str, name str, status str, settings dict\[str, any], description optional\[str], attributes optional\[dict\[str, any]] = none ) > dict\[str, any] payload = { "databaseuuid" database uuid, "collectoruuid" collector uuid, "datatype" datatype, "name" name, "status" status, "settings" settings, "description" description } if attributes is not none payload\["attributes"] = attributes resp = session post(f"{base url}/measurements", json=payload, timeout=60) resp raise for status() return resp json() attributes = { "config" { "uom" "m", "limithi" 3, "limitlo" 7, "valuemax" 0, "valuemin" 10 } } settings = { "type" "sampled", "inputs" {" a" { "type" "measurement", "uuid" "my input measurement uuid", "aggregation" "last" }}, "script" "set tag(\\"a\\", \\"a\\")\ntest = rand float() 10 0\nreturn test a value", "interval" "5s", "intervaloffset" "0s", "evaluateinsufficientdata" false } new calculation = create calculation("my database uuid", "my calculation collector uuid", "number", "mycalculation", "active", settings, "", attributes) print(json dumps(new calculation, indent=2)) successful response { "uuid" "df897a4c 9881 11f0 be39 ca980df018c1", "createdby" "6c8ef372 5c29 11ef 9e88 0242ac12000a", "createdat" "2025 09 23t13 33 21 698758555z", "updatedby" "6c8ef372 5c29 11ef 9e88 0242ac12000a", "updatedat" "2025 09 23t13 33 21 698758555z", "attributes" { "config" { "limithi" 3, "limitlo" 7, "uom" "a", "valuemax" 0, "valuemin" 10 } }, "metadata" null, "organizationuuid" "fbf184b2 5c29 11ef 8bf9 0242ac12000a", "name" "mycalculation", "description" "", "datatype" "number", "status" "active", "collectoruuid" "fbfbc206 5c29 11ef 8bf9 0242ac12000a", "collector" { "uuid" "fbfbc206 5c29 11ef 8bf9 0242ac12000a", "createdby" "6c8ef372 5c29 11ef 9e88 0242ac12000a", "createdat" "2024 08 16t23 48 06 275993z", "updatedby" "6c8ef372 5c29 11ef 9e88 0242ac12000a", "updatedat" "2025 09 14t17 36 31 62295z", "attributes" {}, "metadata" {}, "organizationuuid" "fbf184b2 5c29 11ef 8bf9 0242ac12000a", "settings" { "batchsize" 360, "bufferdiskbatches" 100, "bufferenablediskqueue" false, "buffermaxbatchsize" 5000, "buffermaxbatches" 20, "buffermaxdiskspace" "0mb", "bufferminfreediskspace" "2gb", "bufferprocessinterval" 250, "loglevel" "info", "maxqueryperiod" "12h", "savestaterate" 5, "scripttimeout" 10000, "updaterate" 5000 }, "name" "calculation collector", "collectortype" "calculation", "buildversion" "7 3 3", "buildos" "linux", "buildarch" "amd64", "description" "internal collector for calculations", "status" "active", "measurementsettingsschema" { "$defs" { "inputdatareference" { "properties" { "aggregation" { "description" "the aggregation used", "enum" \[ "count", "integral", "mean", "median", "mode", "spread", "stddev", "sum", "first", "last", "max", "min" ], "examples" \[ "" ], "order" 3, "title" "aggregation", "type" "string" }, "alias" { "description" "an alias for the input measurement name", "order" 4, "title" "alias", "type" "string" }, "name" { "description" "the name of the input measurement", "order" 1, "title" "name", "type" "string" }, "uuid" { "description" "the uuid of the input measurement", "order" 2, "title" "uuid", "type" "string" } }, "required" \[ "uuid", "alias" ], "type" "object" }, "rawsettings" { "properties" { "inputdatareference" { "$ref" "#/$defs/inputdatareference" }, "script" { "order" 4 }, "type" { "const" "raw", "title" "name" } }, "required" \[ "type", "inputdatareference", "script" ] }, "sampledsettings" { "properties" { "inputdatareferences" { "description" "the input measurements", "items" { "$ref" "#/$defs/inputdatareference" }, "order" 3, "title" "inputdatareferences", "type" "array" }, "interval" { "title" "interval", "type" "string" }, "intervaloffset" { "title" "intervaloffset", "type" "string" }, "script" { "$ref" "#/$defs/script", "order" 4 }, "type" { "const" "sampled", "title" "name" } }, "required" \[ "type", "interval", "intervaloffset", "script" ] }, "script" { "description" "the script", "title" "script", "type" "string" } }, "$id" "http //factry io/calculationsettings json", "$schema" "http //json schema org/draft 06/schema#", "oneof" \[ { "$ref" "#/$defs/rawsettings" }, { "$ref" "#/$defs/sampledsettings" } ], "type" "object" }, "settingsschema" { "$id" "http //factry io/calculationcollectorsettings json", "$schema" "http //json schema org/draft 06/schema#", "definitions" {}, "properties" { "batchsize" { "$id" "/properties/batchsize", "default" 3600, "description" "defines the maximum number of points that get processed per run ", "isadvanced" true, "minimum" 1, "order" 2, "title" "batchsize", "type" "integer" }, "bufferdiskbatches" { "$id" "/properties/bufferdiskbatches", "default" 100, "description" "the maximum amount of batches that will be written to a buffer file ", "isadvanced" true, "order" 108, "title" "bufferdiskbatches", "type" "integer" }, "bufferenablediskqueue" { "$id" "/properties/bufferenablediskqueue", "default" true, "description" "enable the disk queue ", "isadvanced" true, "order" 111, "title" "bufferenablediskqueue", "type" "boolean" }, "buffermaxbatchsize" { "$id" "/properties/buffermaxbatchsize", "default" 5000, "description" "the maximum size of a batch ", "isadvanced" true, "order" 106, "title" "buffermaxbatchsize", "type" "integer" }, "buffermaxbatches" { "$id" "/properties/buffermaxbatches", "default" 20, "description" "the maximum amount of batches the buffer will keep in memory ", "isadvanced" true, "order" 107, "title" "buffermaxbatches", "type" "integer" }, "buffermaxdiskspace" { "$id" "/properties/buffermaxdiskspace", "default" "0mb", "description" "the maximum disk space that the buffer files may take up default no limit ", "isadvanced" true, "order" 110, "pattern" "\[0 9]+(t|g|m|k)?b", "title" "buffermaxdiskspace", "type" "string" }, "bufferminfreediskspace" { "$id" "/properties/bufferminfreediskspace", "default" "2gb", "description" "the buffer wont write to more files if the minimum free disk space is reached ", "isadvanced" true, "order" 109, "pattern" "\[0 9]+(t|g|m|k)?b", "title" "bufferminfreediskspace", "type" "string" }, "bufferprocessinterval" { "$id" "/properties/bufferprocessinterval", "default" 250, "description" "the interval in milliseconds that the buffer processes the buffer ", "isadvanced" true, "minimum" 250, "order" 105, "title" "bufferprocessinterval", "type" "integer" }, "loglevel" { "$id" "/properties/loglevel", "default" "info", "description" "the log level for this calculation collector logs ", "enum" \[ "trace", "debug", "info", "warning", "error", "fatal", "panic" ], "isadvanced" true, "order" 6, "title" "loglevel", "type" "string" }, "maxqueryperiod" { "$id" "/properties/maxqueryperiod", "default" "7d", "description" "the maximum query period for a calculation ", "isadvanced" true, "order" 4, "pattern" "^(\\\d+\[w,d,h,m,s])+$", "title" "maxqueryperiod", "type" "string" }, "savestaterate" { "$id" "/properties/savestaterate", "default" 5, "description" "the rate in minutes at which calculation states are saved ", "isadvanced" true, "minimum" 1, "order" 5, "title" "savestaterate", "type" "integer" }, "scripttimeout" { "$id" "/properties/scripttimeout", "default" 10000, "description" "the timeout for a calculation script in ms ", "minimum" 1000, "order" 1, "title" "scripttimeout", "type" "integer" }, "updaterate" { "$id" "/properties/updaterate", "default" 5000, "description" "the update rate at which calculations are evaluated ", "isadvanced" true, "minimum" 1000, "order" 3, "title" "updaterate", "type" "integer" } }, "required" \[], "type" "object" }, "state" {}, "health" { "health" "collecting", "timestamp" "2025 09 23t08 52 29 240207z", "collectoruuid" "fbfbc206 5c29 11ef 8bf9 0242ac12000a" }, "lastseen" "2025 09 23t13 33 21 193490888z", "ipaddress" "", "hauuid" null, "defaultdatabaseuuid" null, "updatecollectorto" null }, "databaseuuid" "19bdd45c 5c2d 11ef ae29 0242ac12000a", "settings" { "evaluateinsufficientdata" false, "inputs" { " a" { "aggregation" "last", "type" "measurement", "uuid" "573a1bb0 5c32 11ef 9cc7 0242ac12000a" } }, "interval" "5s", "intervaloffset" "0s", "script" "set tag(\\"a\\", \\"a\\")\ntest = rand float() 10 0\nreturn test a value", "type" "sampled" }, "labels" null } bulk create calculations this code creates multiple calculations in one request ( my swagger ) note that the payload is an array of json objects, where the structure of each json object is identical to manage calculations docid\ vwq70 g7rg zcnjgseyg put put https //historian mycompany com 18000/api/measurements def create calculations(payload) resp = session put(f"{base url}/measurements", json=payload, timeout=60) resp raise for status() return resp json() payload = \[ { "attributes" { "config" { "uom" "a", "limithi" 1, "limitlo" 1, "valuemax" 1, "valuemin" 1 } }, "organizationuuid" "my organization uuid", "collectoruuid" "my calculation collector uuid", "databaseuuid" "my database uuid", "datatype" "number", "description" "this is a description", "name" "mycalculation1", "settings" { "type" "sampled", "inputs" {" a" { "type" "measurement", "uuid" "xxxxxxx xxxx xxxxxxxxxxxxxx", "aggregation" "last" }}, "script" "test = 6\nreturn rand float() 10 0 a value", "interval" "5s", "intervaloffset" "0s", "evaluateinsufficientdata" false }, "status" "active" }, { "attributes" { "config" { "uom" "a", "limithi" 1, "limitlo" 1, "valuemax" 1, "valuemin" 1 } }, "organizationuuid" "my organization uuid", "collectoruuid" "my calculation collector uuid", "databaseuuid" "my database uuid", "datatype" "number", "description" "this is a description", "name" "mycalculation2", "settings" { "type" "sampled", "inputs" {" a" { "type" "measurement", "uuid" "my input measurement uuid", "aggregation" "last" }}, "script" "test = 6\nreturn rand float() 10 0 a value", "interval" "5s", "intervaloffset" "0s", "evaluateinsufficientdata" false }, "status" "active" } ] create calculations result = create calculations(payload) print(json dumps(create calculations result, indent=2)) successful response { } for historian versions below v8 0 0, the put put https //historian mycompany com 18000/api/measurements endpoint for bulk updates is patch patch https //historian mycompany com 18000/api/measurements instead in v8 0 0 and higher, patch patch https //historian mycompany com 18000/api/measurements still exists, but expects a different data structure this is a breaking change as listed in the v8 docid\ fjib1tgkmrovxrgg hppq