Skip to main content

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.

License: MIT PyPI status badge Python Versions (officially) supported

Unittests status badge Coverage status badge Linting status badge Black status badge

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

osemclient-0.1.2.tar.gz (16.3 kB view hashes)

Uploaded Source

Built Distribution

osemclient-0.1.2-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

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