Skip to main content

Sensorthings API Python Client

The FRaunhofer Opensource SensorThings API Python Client is a python package for the SensorThingsAPI and aims to simplify development of SensorThings enabled client applications

Features

  • CRUD operations
  • Queries on entity lists
  • MultiDatastreams

API

The SensorThingsService class is central to the library. An instance of it represents a SensorThings service and is identified by a URI.

CRUD operations

The source code below demonstrates the CRUD operations for Thing objects. Operations for other entities work similarly.

import frost_sta_client as fsc

url = "exampleserver.com/FROST-Server/v1.1"
auth_handler = fsc.AuthHandler(username="admin", password="admin") # if server is configured for basic auth, else None
service = fsc.SensorThingsService(url, auth_handler=auth_handler)

Creating Entities

from geojson import Point

point = Point((-115.81, 37.24))
location = fsc.Location(name="here", description="and there", location=point, encoding_type='application/geo+json')
 
thing = fsc.Thing(name='new thing',
              description='I am a thing with a location',
              properties={'withLocation': True, 'owner': 'IOSB'})
thing.locations = [location]
service.create(thing)

Querying Entities

Queries to the FROST Server can be modified to include filters, selections or expansions. The return value is always an EntityList object, containing the parsed json response of the server.

things_list = service.things().query().filter('id eq 1').list()

for thing in things_list:
    print("my name is: {}".format(thing.name))

EntityLists

When querying a list of entities that is particularly long, the FROST server divides the list into smaller chunks, replaying to the request with the first chunk accompanied by the link to the next one.

The class EntityList implements the function __iter__ and __next__ which makes it capable of iterating through the entire list of entities, including the calls to all chunks.

things_list = service.things().query().list()

for thing in things_list:
    print("my name is: {}".format(thing.name))

In a case where only the current chunk is supposed to be iterated, the entities list can be used.

things_list = service.things().query().top(20).list()

for thing in things_list.entities:
    print("my name is: {}".format(thing.name))

Queries to related entity lists

For example the Observations of a given Datastream can be queried via

datastream = service.datastreams().find(1)
observations_list = datastream.get_observations().query().filter("result gt 10").list()

Callback function in EntityList

The progress of the loading process can be tracked by supplying a callback function along with a step size. The callback function and the step size must both be provided to the list function (see example below).

If a callback function and a step size are used, the callback function is called every time the step size is reached during the iteration within the for-loop. (Note that the callback function so far only works in combination with a for-loop).

The callback function is called with one argument, which is the current index of the iteration.

def callback_func(loaded_entities):
    print("loaded {} entities!".format(loaded_entities))

service = fsc.SensorThingsService('example_url')

things = service.things().query().list(callback=callback_func, step_size=5)
for thing in things:
    print(thing.name)

DataArrays

DataArrays can be used to make the creation of Observations easier, because with an DataArray only one HTTP Request has to be created.

An example usage looks as follows:

    import frost_sta_client as fsc
    
    service = fsc.SensorThingsService("exampleserver.com/FROST-Server/v1.1")
    dav = fsc.model.ext.data_array_value.DataArrayValue()
    datastream = service.datastreams().find(1)
    foi = service.features_of_interest().find(1)
    components = {dav.Property.PHENOMENON_TIME, dav.Property.RESULT, dav.Property.FEATURE_OF_INTEREST}
    dav.components = components
    dav.datastream = datastream
    obs1 = fsc.Observation(result=3,
                           phenomenon_time='2022-12-19T10:00:00Z',
                           datastream=datastream,
                           feature_of_interest=foi)
    obs2 = fsc.Observation(result=5,
                           phenomenon_time='2022-12-19T10:00:00Z/2022-12-19T11:00:00Z',
                           datastream=datastream,
                           feature_of_interest=foi)
    dav.add_observation(obs1)
    dav.add_observation(obs2)
    dad = fsc.model.ext.data_array_document.DataArrayDocument()
    dad.add_data_array_value(dav)
    result_list = service.observations().create(dad)

Json (De)Serialization

Since not all possible backends that are configurable in jsonpickle handle long floats equally, the backend json module is set to demjson3 per default. The backend can be modified by calling jsonpickle.set_preferred_backend('name_of_preferred_backend') anywhere in the code that uses the client.

Metadata

Release files for frost-sta-client 1.1.53

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for frost-sta-client 1.1.53
File Size Uploaded
frost_sta_client-1.1.53.tar.gz 38.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for frost-sta-client 1.1.53
File Interpreter ABI Platform
frost_sta_client-1.1.53-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 100.4 kB

Release files / frost_sta_client-1.1.53.tar.gz

Download URL frost_sta_client-1.1.53.tar.gz
Size 38.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6701ed3019e801f225ccdb4462129df13bad9a9e7f1c4b35cc9758c4a9fe028d
BLAKE2b-256 checksum
How to use checksums
5d7185f70389b94ec827882f1f4487a5912d7063f53b0f65ed90647bd6a0f0b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / frost_sta_client-1.1.53-py2.py3-none-any.whl

Download URL frost_sta_client-1.1.53-py2.py3-none-any.whl
Size 61.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ee680d2149c0342a89c312e88eadf6b495114b424d1d4fdf416f0cd8cafe2b2f
BLAKE2b-256 checksum
How to use checksums
33c7298173a5698eb6cbb637f86f7b43a5b93c11fb1e0c78a77a6c5a27451c38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

1.1.53 This release

2 release files

1.1.52

2 release files

1.1.51

2 release files

1.1.50

2 release files

1.1.48

2 release files

1.1.46

2 release files

1.1.44

2 release files

1.1.40

2 release files

1.1.38

2 release files

1.1.37

2 release files

1.1.36

2 release files

1.1.35

2 release files

1.1.34

2 release files

1.1.33

2 release files

1.1.32

2 release files

1.1.31

2 release files

1.1.30

2 release files

1.1.29

2 release files

1.1.28

2 release files

1.1.27

2 release files

1.1.26

2 release files

1.1.23

2 release files

1.1.21

2 release files

1.1.20

2 release files

1.1.19

2 release files

1.1.18

2 release files

1.1.17

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page