Skip to main content

An easy to use SensorThings API Client written in Python

Project description

stapy

Latest Release Build Status Python Version Language grade: Python Codecov

This is an easy to use SensorThings API Client written in Python

The SensorThings API (STA) is an OGC standard for IoT device sensing data.
A server implementation of the STA can be found here FROST.
For more (advanced) information about the SensorThings API see the official OGC documentation.

Installation

stapy is compatible with Python 3.6+ and the recommended way to install is via pip

pip install stapy

Usage

stapy can be used both form the command line (in two different ways) and as a Python library.

STA_URL

At first it is necessary to set the URL of the STA. Optionally it is also possible to set credentials for a basic authentication. Within the CLI this can be achieved as follows:

stapy -u {URL} ({USR} {PWD})

stapy can of course be also run as a Python module(python -m stapy)

The URL and credentials can also be set from within a Python script:

>>> import stapy

>>> stapy.set_sta_url({URL})
>>> stapy.set_credentials({USR}, {PWD})

CLI - Interactive

The interactive mode is the easiest one to use but can not be used programmatically. Therefore it is probably a good starting point to get familiar with the STA. The interactive mode can be invoked in the following way.

stapy -i

Currently it does support POST, PATCH and DELETE requests.

CLI - Normal

The normal command line mode is a bit more difficult to use but can be automated.

stapy --help

Should give sufficient information on how two use it properly. As the interactive mode it does support POST, PATCH and DELETE requests.

Library

This is the Python interface to the SensorThings API (stapy is meant to be used as Python library). Therefore it supports all requests (POST, PATCH, DELETE and GET).

The relevant classes can be found within the files entity.py, delete.py, post.py, patch.py and query.py in the sta sub-module.

The following syntax can be used to create new entities:

>>> from stapy import Post

>>> Post.observed_property("TestProp", "TestProp-Desc", "TestProp-Def")

To understand which arguments are available and mandatory it is advisable to have a look at the STA-Docs and/or use the interactive mode of stapy.

Following is one example of a GET request:

>>> from stapy import Query, Entity

>>> results, times = Query(Entity.Observation).select("result", "phenomenonTime").order("result").get_data_sets()

results afterwards contains all results of the present Observations in ascending order.
times contains the respective times for the results.

stapy does support all GET query options that are available for the STA. Some examples are select, filter, orderby and skip. These can be chained together as seen in the example above.

Further use-cases and applications can be found in the examples.

Development

To build this project, run python setup.py build. To execute the unit tests, run python setup.py test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stapy-0.3.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stapy-0.3.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file stapy-0.3.0.tar.gz.

File metadata

  • Download URL: stapy-0.3.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2

File hashes

Hashes for stapy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0f0d93d616aa7a0cd7a1f5916d546ab24ec5d48764e2b1c1a275b66ff6081d10
MD5 76ed8520239658c087d5ca978b1a7ecd
BLAKE2b-256 a450197680fc27b38ce91034f476911027ae33be0f123d96ed1c592003fc53a0

See more details on using hashes here.

File details

Details for the file stapy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: stapy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2

File hashes

Hashes for stapy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc28ba8b0b9f6eb0512340ca47d0c0f7f998d04b31f3046ffabcc8e39185cd1
MD5 9806a4971b880b0d33245600c901ad72
BLAKE2b-256 ba0e0be05736e576e5898996efc9da5e579295ddaf477879e13ed07fd3f8d898

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page