Skip to main content

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.

Metadata

Release files for osemclient 0.1.2

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

Source distribution (sdist)

Source distribution for osemclient 0.1.2
File Size Uploaded
osemclient-0.1.2.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osemclient 0.1.2
File Interpreter ABI Platform
osemclient-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / osemclient-0.1.2.tar.gz

Download URL osemclient-0.1.2.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b17c3debb6e7d5999f8a72b959d56b8cd4c1fd67df99fc9a49ad06a91f61c358
BLAKE2b-256 checksum
How to use checksums
12b062f914751010eec28648f89ee5fd5be301137982b6b42395456e1a411ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / osemclient-0.1.2-py3-none-any.whl

Download URL osemclient-0.1.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fe1d8440e6cf2f916c0e55f964466f586586f32542472bdb282f7274756e1ca
BLAKE2b-256 checksum
How to use checksums
1b74861dc4a486dd2be054161ed30db0a4850f1e9c9d7d50fceac0e2f7d5a85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 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