https://github.com/zMoooooritz/stapy
An easy to use SensorThings API Client written in Python
https://github.com/zMoooooritz/stapy
api cli data-science database ogc python sensor sensor-data sensorthings sensorthings-api
Last synced: 11 months ago
JSON representation
An easy to use SensorThings API Client written in Python
- Host: GitHub
- URL: https://github.com/zMoooooritz/stapy
- Owner: zMoooooritz
- License: mit
- Created: 2021-08-19T12:07:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-30T18:21:50.000Z (over 2 years ago)
- Last Synced: 2025-04-18T11:44:29.891Z (12 months ago)
- Topics: api, cli, data-science, database, ogc, python, sensor, sensor-data, sensorthings, sensorthings-api
- Language: Python
- Homepage:
- Size: 147 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-sensorthings-api - stapy
README
# stapy
[](https://github.com/zMoooooritz/stapy/releases)
[](https://github.com/zMoooooritz/stapy/actions)
[](https://pypi.org/project/stapy/)
[](https://codecov.io/github/zMoooooritz/stapy?branch=master)
This is an easy to use SensorThings API Client written in Python
> [!IMPORTANT]
> This project is no longer being actively maintained.
> Since the STA standard keeps evolving, the feature set of this client implementation will keep falling behind.
> However the project [Frost-Python-Client](https://github.com/FraunhoferIOSB/FROST-Python-Client) is actively maintained and provides a seemingly complete API.
The SensorThings API (STA) is an [OGC](https://www.osgeo.org/partners/ogc/) standard for IoT device sensing data.\
A server implementation of the STA can be found here [FROST](https://github.com/FraunhoferIOSB/FROST-Server).\
For more (advanced) information about the SensorThings API see the official OGC [documentation](http://developers.sensorup.com/docs).
## Installation
`stapy` is compatible with Python 3.7+ and the recommended way to install is via [pip](https://pip.pypa.io/en/stable/)
```bash
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:
```bash
stapy -u {URL}
stapy -c {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:
```python
>>> 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.
```bash
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.
```bash
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](https://github.com/zMoooooritz/stapy/tree/master/stapy/sta) sub-module.
The following syntax can be used to create new entities:
```python
>>> 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](https://developers.sensorup.com/docs/) and/or use the interactive mode of stapy.
Following is one example of a `GET` request:
```python
>>> 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](https://developers.sensorup.com/docs/#queryparameters).
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](https://github.com/zMoooooritz/stapy/tree/master/examples).
## Development
To build this project, run `python setup.py build`. To execute the unit tests, run `python setup.py test`.