aiohttp-based client for OpenSenseMap API
Project description
osem-python-client
osemclient
is an async Python client with fully typed model classes for the OpenSenseMap REST API.
It is based on aiohttp and Pydantic.
Usage
pip install osemclient
import asyncio
from osemclient.client import OpenSenseMapClient
async def get_recent_measurements(sensebox_id: str):
"""
downloads the latest 10_000 measurements for the given sensebox id
"""
client = OpenSenseMapClient()
try:
measurements = [x async for x in client.get_measurements_with_sensor_metadata(sensebox_id=sensebox_id)]
print(
f"There are {len(measurements)} measurements available: "
+ ", ".join(str(ms) for ms in measurements[0:3])
+ " ..."
)
assert any(m for m in measurements if m.unit == "°C") # there are temperature measurements
assert any(m for m in measurements if m.unit == "hPa") # there are air pressure measurements
# and many more
finally:
await client.close_session()
if __name__ == "__main__":
asyncio.run(get_recent_measurements(sensebox_id="621f53cdb527de001b06ad5e"))
Methods that return measurement values are async generators. This allows for kind of streaming the data from the OSeM API and avoids large bloating lists in memory.
State of this Project
This project is very alpha and more a proof of concept. It only supports two GET API endpoints as of 2023-12-18 and even those are not covered completely. If you really want to use it, there's still work to be done but this project might be a good foundation.
Development
Check the instructions in our Python Template Repository. tl;dr: tox.
Contribute
You are very welcome to contribute to this template repository by opening a pull request against the main branch.
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
Built Distribution
File details
Details for the file osemclient-0.1.2.tar.gz
.
File metadata
- Download URL: osemclient-0.1.2.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b17c3debb6e7d5999f8a72b959d56b8cd4c1fd67df99fc9a49ad06a91f61c358 |
|
MD5 | 4909173d1cec42e05a9651f66dc4b58b |
|
BLAKE2b-256 | 12b062f914751010eec28648f89ee5fd5be301137982b6b42395456e1a411ee4 |
File details
Details for the file osemclient-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: osemclient-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fe1d8440e6cf2f916c0e55f964466f586586f32542472bdb282f7274756e1ca |
|
MD5 | 3e91abcfa2cb220fe2786b5542b650c4 |
|
BLAKE2b-256 | 1b74861dc4a486dd2be054161ed30db0a4850f1e9c9d7d50fceac0e2f7d5a85e |