API reference
datafarmclient.DatafarmClient
DatafarmClient(api_url)
Base DatafarmClient class, the main entrypoint to use the client.
| ATTRIBUTE | DESCRIPTION |
|---|---|
api_url |
The instantiated api url.
|
timeseries |
The timeseries subclass
|
variables |
The variables subclass
|
entities |
The entities subclass that you instantiate with an Entitytype
|
Examples:
>>> from datafarmclient import DatafarmClient
>>> client = DatafarmClient(api_url=api_url)
>>> client.login(api_key=api_key)
True
Base-class initializer.
| PARAMETER | DESCRIPTION |
|---|---|
api_url
|
The URL for which api server to use.
TYPE:
|
Source code in datafarmclient/base.py
33 34 35 36 37 38 39 40 41 42 43 44 | |
api_url
instance-attribute
api_url = validate_api_url(api_url)
session
instance-attribute
session = Session()
connected
instance-attribute
connected = False
time_series_source_descriptions
cached
property
time_series_source_descriptions
units
cached
property
units
time_series_types
cached
property
time_series_types
time_series_status
cached
property
time_series_status
qualities
cached
property
qualities
parameters
cached
property
parameters
medias
cached
property
medias
locations
cached
property
locations
quality_level_to_name
cached
property
quality_level_to_name
quality_name_to_level
cached
property
quality_name_to_level
validate_api_url
staticmethod
validate_api_url(host_address)
Source code in datafarmclient/base.py
46 47 48 49 50 51 52 53 | |
login
login(api_key)
Connect to the Datafarm API.
| PARAMETER | DESCRIPTION |
|---|---|
api_key
|
A valid API key for the class api url.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether or not you succesfully logged in. |
Source code in datafarmclient/base.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
logoff
logoff()
Close the connection to the Datafarm API.
Source code in datafarmclient/base.py
84 85 86 87 88 89 90 91 | |
list
list(class_id)
Source code in datafarmclient/base.py
93 94 95 | |
datafarmclient.Entities
Entities(class_id, client)
A Entitites subclass for the base class.
Entities need to be instantiated with an entitytype.
| PARAMETER | DESCRIPTION |
|---|---|
class_id
|
Entitytype specifying which entity to work with
TYPE:
|
client
|
The base client allowing the subclass to use the shared session and client methods.
TYPE:
|
Source code in datafarmclient/entities/_entities.py
22 23 24 25 26 27 28 29 30 31 | |
class_id
instance-attribute
class_id = class_id
create
create(id_name, fields=None)
Create an entity.
| PARAMETER | DESCRIPTION |
|---|---|
id_name
|
The ID name of the new entity.
TYPE:
|
fields
|
The fields of the new entity.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Id of the newly created entity |
| RAISES | DESCRIPTION |
|---|---|
EntityExistsError
|
The entity already exists in the system |
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
exists
exists(id_name, fields=None)
Check if an entity exists or not
| PARAMETER | DESCRIPTION |
|---|---|
id_name
|
The ID name of the entity.
TYPE:
|
fields
|
The fields of the entity.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
A boolean result based on whether or not an entity |
bool
|
with that ID name already exists |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
get
get(id_name)
Get the ID of an entity.
| PARAMETER | DESCRIPTION |
|---|---|
id_name
|
The ID name of the entity.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The id of the entity |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
update
update(entity_id, fields=None)
Update an entity.
| PARAMETER | DESCRIPTION |
|---|---|
entity_id
|
The ID of the entity.
TYPE:
|
fields
|
The fields to update of the entity.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
delete
delete(entity_id)
Delete an entity.
| PARAMETER | DESCRIPTION |
|---|---|
entity_id
|
The ID of the entity to delete.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
metadata
metadata()
Get the metadata of an EntityType.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Pandas DataFrame containing the results |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
list
list(fields=None)
List all entities of the chosen type.
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Pandas DataFrame containing the results |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/entities/_entities.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
datafarmclient.TimeSeries
TimeSeries(client)
A TimeSeries subclass for the base class.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
The base client allowing the subclass to use the shared session and client methods.
TYPE:
|
Source code in datafarmclient/timeseries/_timeseries.py
35 36 37 38 39 40 41 | |
get_data
get_data(
time_series_id,
start=datetime(1900, 1, 1, 0, 0, 0, 0),
end=datetime(2100, 1, 1, 0, 0, 0, 0),
fields=None,
qualities=None,
aggregation=None,
limit=0,
ascending=True,
)
Get data from Datafarm.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to get data from.
TYPE:
|
start
|
The start of the range to get data from.
TYPE:
|
end
|
The end of the range to get data from.
TYPE:
|
fields
|
fields/columns to return
TYPE:
|
qualities
|
Filter the data by qualities.
TYPE:
|
aggregation
|
Complex data structure that gets constructed with create_aggregation() or create_resample().
TYPE:
|
limit
|
The maximum number of rows to return.
TYPE:
|
ascending
|
Whether to sort the data in ascending order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[DataFrame]
|
List of dataframes. |
| RAISES | DESCRIPTION |
|---|---|
EntityNotFoundError
|
An error occurs if no timeseries are found. |
Source code in datafarmclient/timeseries/_timeseries.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
delete_data
delete_data(
time_series_id, timestamps=None, start=None, end=None
)
Delete data from a time series. Either timestamps or start and end must be provided.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to delete data from.
TYPE:
|
timestamps
|
The timestamps to delete.
TYPE:
|
start
|
The start of the range to delete data from.
TYPE:
|
end
|
The end of the range to delete data from. Note that this is NOT inclusive.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
update_data_quality
update_data_quality(time_series_id, qualities)
Update the quality of data in a time series.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to update.
TYPE:
|
qualities
|
The qualities to set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
update_data_quality_range
update_data_quality_range(
time_series_id, quality, start, end
)
Update the quality of data in a range in a time series.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to update.
TYPE:
|
start
|
The start of the range to update data quality from.
TYPE:
|
end
|
The end of the range to update data quality from. Note that this is NOT inclusive.
TYPE:
|
quality
|
The quality to set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
insert_data
insert_data(
time_series_id,
data,
bulk_insert=False,
values_col="Data",
qualities_col="QualityTxt",
confidence_col="Confidence",
duration_col="Duration",
filepath_col="FilePath",
)
Insert data into a time series.
It is assumed that the dataframe has a DateTimeIndex and not a TimeStamp column
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to update.
TYPE:
|
data
|
The dataframe containing the data to insert.
TYPE:
|
bulk_insert
|
bool = False,
TYPE:
|
values_col
|
str = "Data",
TYPE:
|
qualities_col
|
str = "QualityTxt",
TYPE:
|
confidence_col
|
str = "Confidence",
TYPE:
|
duration_col
|
str = "Duration",
TYPE:
|
filepath_col
|
str = "FilePath",
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
statistics
statistics(time_series_id)
Get statistics for a time series or a list of time series.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to get statistics for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Pandas dataframe with statistics about the timeseries dataset. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
list
list()
Source code in datafarmclient/timeseries/_timeseries.py
314 315 316 | |
latest_values
latest_values(time_series_id, before=None)
Get data from Datafarm.
| PARAMETER | DESCRIPTION |
|---|---|
time_series_id
|
The time series to get data from.
TYPE:
|
before
|
Get values from before this timestamp.
TYPE:
|
Returns List of dataframes
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/timeseries/_timeseries.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
create_resample
staticmethod
create_resample(
*,
method,
repetition_type,
period="apHour",
period_offset=0,
user_def_period=0,
user_def_time_ref=now(),
)
Helper function for creating a timeseries resampling object.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
Choose from 2 different resampling methods.
TYPE:
|
repetition_type
|
Stairs or inverted stairs.
TYPE:
|
period
|
Aggregation period to use.
TYPE:
|
period_offset
|
An optional offset to use for the period. This is ignored for period=apUserDefinedSeconds
TYPE:
|
user_def_period
|
If period=apUserDefinedSeconds then this parameter is used
TYPE:
|
user_def_time_ref
|
If period=apUserDefinedSeconds then this parameter is used
TYPE:
|
Returns TAggregation
Source code in datafarmclient/timeseries/_timeseries.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
create_aggregation
staticmethod
create_aggregation(
*,
method,
period,
method_constant=0,
direction="pdStraight",
period_offset=0,
user_def_period=0,
user_def_time_ref=now(),
)
Helper function for creating a timeseries aggregation object.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
Choose from 10 different aggregation methods.
TYPE:
|
period
|
Aggregation period to use.
TYPE:
|
period_offset
|
An optional offset to use for the period. This is ignored for period=apUserDefinedSeconds
TYPE:
|
direction
|
How to do the aggregation.
TYPE:
|
user_def_period
|
If period=apUserDefinedSeconds then this parameter is used.
TYPE:
|
user_def_time_ref
|
If period=apUserDefinedSeconds then this parameter is used.
TYPE:
|
Returns TAggregation
Source code in datafarmclient/timeseries/_timeseries.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
datafarmclient.Variables
Variables(client)
A Variables subclass for the base class.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
The base client allowing the subclass to use the shared session and client methods.
TYPE:
|
Source code in datafarmclient/variables/_variables.py
16 17 18 19 20 21 22 | |
get_object_variable
get_object_variable(
name, output_dir=None, output_path=None
)
Get an object variable.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the variable.
TYPE:
|
output_dir
|
The directory to save the object to. The file name will be read from the system. Defaults to None.
TYPE:
|
output_path
|
The path to save the object to. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[str, bytes]
|
If neither |
Union[str, bytes]
|
the object is returned as bytes. |
Union[str, bytes]
|
Otherwise, the object is saved to the specified path. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception. |
VariableNotFoundError
|
If specificed variable doesn't exists. |
ValueError
|
If variable is not an object. |
Source code in datafarmclient/variables/_variables.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
set_object_variable
set_object_variable(name, file_path)
Set an object in the session.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the object.
TYPE:
|
file_path
|
The file path of the object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception. |
Source code in datafarmclient/variables/_variables.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
create_category
create_category(name)
Create a new variable category.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the category.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Id of the newly created variable category. |
| RAISES | DESCRIPTION |
|---|---|
EntityExistsError
|
The entity already exists in the system. |
HttpError
|
Requests threw an exception. |
Source code in datafarmclient/variables/_variables.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
create_type
create_type(name)
Create a new variable type.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Id of the newly created variable type. |
| RAISES | DESCRIPTION |
|---|---|
EntityExistsError
|
The entity already exists in the system. |
HttpError
|
Requests threw an exception. |
Source code in datafarmclient/variables/_variables.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
delete_category
delete_category(name)
Delete a variable category
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the category.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/variables/_variables.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
delete_type
delete_type(name)
Delete a variable type
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Response
|
Response from the API. |
| RAISES | DESCRIPTION |
|---|---|
HttpError
|
Requests threw an exception |
Source code in datafarmclient/variables/_variables.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
Schemas
EntityType
- enTimeSeries
- enTimeSeriesQuality
- enTimeSeriesDatasourceDescription
- enTimeSeriesType
- enTimeSeriesStatus
- enTimeSeriesUnit
- enTimeSeriesMedia
- enTimeSeriesParameter
- enLocation
- enGlobalVariable
- enGlobalVariableCategory
- enGlobalVariableType