Skip to content

PulseEcoAPI

PulseEcoAPI

Bases: PulseEcoAPIBase

Low level unsafe pulse.eco API wrapper.

Source code in pulseeco/api/pulse_eco_api.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
class PulseEcoAPI(PulseEcoAPIBase):
    """Low level unsafe pulse.eco API wrapper."""

    def __init__(
        self,
        city_name: str,
        auth: tuple[str, str] | None = None,
        base_url: str = PULSE_ECO_BASE_URL_FORMAT,
        session: None = None,
        client: CLIENT | None = None,
        async_client: ASYNC_CLIENT | None = None,
    ) -> None:
        """Initialize the pulse.eco API wrapper.

        :param city_name: the city name
        :param auth: a tuple of (email, password), defaults to None
        :param base_url: the base URL of the API, defaults to
            'https://{city_name}.pulse.eco/rest/{end_point}'
        :param session: deprecated, use client and async_client instead
        :param client: a sync http client, supported types are:
            requests.Session, httpx.Client,
            defaults to None which uses a new requests.Session for each request,
            use a context managed session for better performance and resource management
        :param async_client: an async http client, supported types are:
            aiohttp.ClientSession, httpx.AsyncClient,
            defaults to None which will use the sync client
        """
        self.city_name = city_name

        if base_url is not None and PULSE_ECO_BASE_URL_FORMAT_ENV_KEY in os.environ:
            base_url = os.environ[PULSE_ECO_BASE_URL_FORMAT_ENV_KEY]

        if session is not None:  # pragma: no cover
            warnings.warn(
                "The `session` parameter is deprecated. "
                "Use `client` and `async_client` instead.",
                DeprecationWarning,
                stacklevel=2,
            )

        client = client if client is not None else session

        self._client: CLIENT

        if client is not None:
            self._client = client
        else:
            self._client = get_fallback_sync_client()

        self._async_client = async_client

        if auth is None:
            auth = get_auth_from_env(city_name=city_name)

        self._auth = auth

        self._base_url = base_url

    def _base_request(
        self, end_point: str, params: dict[str, Any] | None = None
    ) -> Any:  # noqa: ANN401
        """Make a request to the PulseEco API.

        :param end_point: an end point of the API
        :param params: get parameters, defaults to None
        :return: the response json
        """
        if params is None:
            params = {}
        url = self._base_url.format(city_name=self.city_name, end_point=end_point)

        # httpx does not support auth None
        if self._auth is not None:
            response = self._client.get(url, params=params, auth=self._auth)
        else:
            response = self._client.get(url, params=params)
        response.raise_for_status()

        return response.json()

    async def _abase_request(
        self, end_point: str, params: dict[str, Any] | None = None
    ) -> Any:  # noqa: ANN401
        """Make an async request to the PulseEco API.

        :param end_point: an end point of the API
        :param params: get parameters, defaults to None
        :return: the response json
        """
        if self._async_client is None:
            return self._base_request(end_point, params)

        if params is None:
            params = {}

        url = self._base_url.format(city_name=self.city_name, end_point=end_point)

        # httpx does not support auth None
        if self._auth is not None:
            response = await self._async_client.get(url, params=params, auth=self._auth)
        else:
            response = await self._async_client.get(url, params=params)
        response.raise_for_status()

        # In case of aiohttp, the response.json() is a coroutine function
        if inspect.iscoroutinefunction(response.json):
            return await response.json()
        return response.json()

    def sensors(self) -> list[Sensor]:
        """Get all sensors for a city.

        :return: a list of sensors
        """
        return cast(List[Sensor], self._base_request("sensor"))

    async def asensors(self) -> list[Sensor]:
        """Get all sensors for a city.

        :return: a list of sensors
        """
        return cast(List[Sensor], await self._abase_request("sensor"))

    def sensor(self, sensor_id: str) -> Sensor:
        """Get a sensor by it's ID

        :param sensor_id: the unique ID of the sensor
        :return: a sensor
        """
        return cast(Sensor, self._base_request(f"sensor/{sensor_id}"))

    async def asensor(self, sensor_id: str) -> Sensor:
        """Get a sensor by it's ID

        :param sensor_id: the unique ID of the sensor
        :return: a sensor
        """
        return cast(Sensor, await self._abase_request(f"sensor/{sensor_id}"))

    def data_raw(
        self,
        from_: str | datetime.datetime,
        to: str | datetime.datetime,
        type: str | None = None,
        sensor_id: str | None = None,
    ) -> list[DataValueRaw]:
        """Get raw data for a city.

        :param from_: the start datetime of the data
            as a datetime object or an isoformat string
        :param to: the end datetime of the data
            as a datetime object or an isoformat string
        :param type: the data value type, defaults to None
        :param sensor_id: the unique ID of the sensor, defaults to None
        :return: a list of data values
        """
        if sensor_id is None and type is None:
            warnings.warn(
                "Warning! If you encounter an error, "
                "you should probably specify either sensor_id or type.",
                stacklevel=2,
            )
        data: list[DataValueRaw] = []
        datetime_spans = split_datetime_span(from_, to, DATA_RAW_MAX_SPAN)
        for from_temp, to_temp in datetime_spans:
            params = {
                "sensorId": sensor_id,
                "type": type,
                "from": convert_datetime_to_str(from_temp),
                "to": convert_datetime_to_str(to_temp),
            }
            params = {k: v for k, v in params.items() if v is not None}
            data_value = cast(
                List[DataValueRaw],
                self._base_request("dataRaw", params=params),
            )
            data += data_value
        return data

    async def adata_raw(
        self,
        from_: str | datetime.datetime,
        to: str | datetime.datetime,
        type: str | None = None,
        sensor_id: str | None = None,
    ) -> list[DataValueRaw]:
        """Get raw data for a city.

        :param from_: the start datetime of the data
            as a datetime object or an isoformat string
        :param to: the end datetime of the data
            as a datetime object or an isoformat string
        :param type: the data value type, defaults to None
        :param sensor_id: the unique ID of the sensor, defaults to None
        :return: a list of data values
        """
        if sensor_id is None and type is None:
            warnings.warn(
                "Warning! If you encounter an error, "
                "you should probably specify either sensor_id or type.",
                stacklevel=2,
            )
        coroutines: list[asyncio.Future[list[DataValueRaw]]] = []
        datetime_spans = split_datetime_span(from_, to, DATA_RAW_MAX_SPAN)
        for from_temp, to_temp in datetime_spans:
            params = {
                "sensorId": sensor_id,
                "type": type,
                "from": convert_datetime_to_str(from_temp),
                "to": convert_datetime_to_str(to_temp),
            }
            params = {k: v for k, v in params.items() if v is not None}
            coroutines.append(
                cast(
                    "asyncio.Future[list[DataValueRaw]]",
                    self._abase_request("dataRaw", params=params),
                )
            )
        return [
            data
            for data_value in await asyncio.gather(*coroutines)
            for data in data_value
        ]

    def avg_data(
        self,
        period: str,
        from_: str | datetime.datetime,
        to: str | datetime.datetime,
        type: str,
        sensor_id: str | None = None,
    ) -> list[DataValueAvg]:
        """Get average data for a city.

        :param period: the period of the average data (day, week, month)
        :param from_: the start datetime of the data
            as a datetime object or an isoformat string
        :param to: the end datetime of the data
            as a datetime object or an isoformat string
        :param type: the data value type
        :param sensor_id: the unique ID of the sensor, defaults to None
        :return: a list of average data values
        """
        if period not in {"day", "week", "month"}:
            warnings.warn(
                "Warning! Invalid value for period. "
                "Should be one of: day, week, month",
                stacklevel=2,
            )
        data: list[DataValueAvg] = []
        datetime_spans = split_datetime_span(from_, to, AVG_DATA_MAX_SPAN)
        for from_temp, to_temp in datetime_spans:
            params = {
                "sensorId": sensor_id,
                "type": type,
                "from": convert_datetime_to_str(from_temp),
                "to": convert_datetime_to_str(to_temp),
            }
            params = {k: v for k, v in params.items() if v is not None}
            data_value = cast(
                List[DataValueAvg],
                self._base_request(f"avgData/{period}", params=params),
            )
            data += data_value
        return data

    async def aavg_data(
        self,
        period: str,
        from_: str | datetime.datetime,
        to: str | datetime.datetime,
        type: str,
        sensor_id: str | None = None,
    ) -> list[DataValueAvg]:
        """Get average data for a city.

        :param period: the period of the average data (day, week, month)
        :param from_: the start datetime of the data
            as a datetime object or an isoformat string
        :param to: the end datetime of the data
            as a datetime object or an isoformat string
        :param type: the data value type
        :param sensor_id: the unique ID of the sensor, defaults to None
        :return: a list of average data values
        """
        if period not in {"day", "week", "month"}:
            warnings.warn(
                "Warning! Invalid value for period. "
                "Should be one of: day, week, month",
                stacklevel=2,
            )
        coroutines: list[asyncio.Future[list[DataValueAvg]]] = []
        datetime_spans = split_datetime_span(from_, to, AVG_DATA_MAX_SPAN)
        for from_temp, to_temp in datetime_spans:
            params = {
                "sensorId": sensor_id,
                "type": type,
                "from": convert_datetime_to_str(from_temp),
                "to": convert_datetime_to_str(to_temp),
            }
            params = {k: v for k, v in params.items() if v is not None}
            coroutines.append(
                cast(
                    "asyncio.Future[list[DataValueAvg]]",
                    self._abase_request(f"avgData/{period}", params=params),
                )
            )
        return [
            data
            for data_value in await asyncio.gather(*coroutines)
            for data in data_value
        ]

    def data24h(self) -> list[DataValueRaw]:
        """Get 24h data for a city.

        The data values are sorted ascending by their timestamp.

        :return: a list of data values for the past 24 hours
        """
        return cast(List[DataValueRaw], self._base_request("data24h"))

    async def adata24h(self) -> list[DataValueRaw]:
        """Get 24h data for a city.

        The data values are sorted ascending by their timestamp.

        :return: a list of data values for the past 24 hours
        """
        return cast(List[DataValueRaw], await self._abase_request("data24h"))

    def current(self) -> list[DataValueRaw]:
        """Get the last received valid data for each sensor in a city

        Will not return sensor data older than 2 hours.

        :return: a list of current data values
        """
        return cast(List[DataValueRaw], self._base_request("current"))

    async def acurrent(self) -> list[DataValueRaw]:
        """Get the last received valid data for each sensor in a city

        Will not return sensor data older than 2 hours.

        :return: a list of current data values
        """
        return cast(List[DataValueRaw], await self._abase_request("current"))

    def overall(
        self,
    ) -> Overall:
        """Get the current average data for all sensors per value for a city.

        ## Example:

        ```python
        {
            'cityName': 'skopje',
            'values': {
                'no2': '22',
                'o3': '4',
                'pm25': '53',
                'pm10': '73',
                'temperature': '7',
                'humidity': '71',
                'pressure': '992',
                'noise_dba': '43'
            }
        }
        ```

        :return: the overall data for the city
        """
        return cast(Overall, self._base_request("overall"))

    async def aoverall(
        self,
    ) -> Overall:
        """Get the current average data for all sensors per value for a city.

        ## Example:

        ```python
        {
            'cityName': 'skopje',
            'values': {
                'no2': '22',
                'o3': '4',
                'pm25': '53',
                'pm10': '73',
                'temperature': '7',
                'humidity': '71',
                'pressure': '992',
                'noise_dba': '43'
            }
        }
        ```

        :return: the overall data for the city
        """
        return cast(Overall, await self._abase_request("overall"))

__init__(city_name, auth=None, base_url=PULSE_ECO_BASE_URL_FORMAT, session=None, client=None, async_client=None)

Initialize the pulse.eco API wrapper.

Parameters:

Name Type Description Default
city_name str

the city name

required
auth tuple[str, str] | None

a tuple of (email, password), defaults to None

None
base_url str

the base URL of the API, defaults to 'https://{city_name}.pulse.eco/rest/{end_point}'

PULSE_ECO_BASE_URL_FORMAT
session None

deprecated, use client and async_client instead

None
client CLIENT | None

a sync http client, supported types are: requests.Session, httpx.Client, defaults to None which uses a new requests.Session for each request, use a context managed session for better performance and resource management

None
async_client ASYNC_CLIENT | None

an async http client, supported types are: aiohttp.ClientSession, httpx.AsyncClient, defaults to None which will use the sync client

None
Source code in pulseeco/api/pulse_eco_api.py
def __init__(
    self,
    city_name: str,
    auth: tuple[str, str] | None = None,
    base_url: str = PULSE_ECO_BASE_URL_FORMAT,
    session: None = None,
    client: CLIENT | None = None,
    async_client: ASYNC_CLIENT | None = None,
) -> None:
    """Initialize the pulse.eco API wrapper.

    :param city_name: the city name
    :param auth: a tuple of (email, password), defaults to None
    :param base_url: the base URL of the API, defaults to
        'https://{city_name}.pulse.eco/rest/{end_point}'
    :param session: deprecated, use client and async_client instead
    :param client: a sync http client, supported types are:
        requests.Session, httpx.Client,
        defaults to None which uses a new requests.Session for each request,
        use a context managed session for better performance and resource management
    :param async_client: an async http client, supported types are:
        aiohttp.ClientSession, httpx.AsyncClient,
        defaults to None which will use the sync client
    """
    self.city_name = city_name

    if base_url is not None and PULSE_ECO_BASE_URL_FORMAT_ENV_KEY in os.environ:
        base_url = os.environ[PULSE_ECO_BASE_URL_FORMAT_ENV_KEY]

    if session is not None:  # pragma: no cover
        warnings.warn(
            "The `session` parameter is deprecated. "
            "Use `client` and `async_client` instead.",
            DeprecationWarning,
            stacklevel=2,
        )

    client = client if client is not None else session

    self._client: CLIENT

    if client is not None:
        self._client = client
    else:
        self._client = get_fallback_sync_client()

    self._async_client = async_client

    if auth is None:
        auth = get_auth_from_env(city_name=city_name)

    self._auth = auth

    self._base_url = base_url

aavg_data(period, from_, to, type, sensor_id=None) async

Get average data for a city.

Parameters:

Name Type Description Default
period str

the period of the average data (day, week, month)

required
from_ str | datetime

the start datetime of the data as a datetime object or an isoformat string

required
to str | datetime

the end datetime of the data as a datetime object or an isoformat string

required
type str

the data value type

required
sensor_id str | None

the unique ID of the sensor, defaults to None

None

Returns:

Type Description
list[DataValueAvg]

a list of average data values

Source code in pulseeco/api/pulse_eco_api.py
async def aavg_data(
    self,
    period: str,
    from_: str | datetime.datetime,
    to: str | datetime.datetime,
    type: str,
    sensor_id: str | None = None,
) -> list[DataValueAvg]:
    """Get average data for a city.

    :param period: the period of the average data (day, week, month)
    :param from_: the start datetime of the data
        as a datetime object or an isoformat string
    :param to: the end datetime of the data
        as a datetime object or an isoformat string
    :param type: the data value type
    :param sensor_id: the unique ID of the sensor, defaults to None
    :return: a list of average data values
    """
    if period not in {"day", "week", "month"}:
        warnings.warn(
            "Warning! Invalid value for period. "
            "Should be one of: day, week, month",
            stacklevel=2,
        )
    coroutines: list[asyncio.Future[list[DataValueAvg]]] = []
    datetime_spans = split_datetime_span(from_, to, AVG_DATA_MAX_SPAN)
    for from_temp, to_temp in datetime_spans:
        params = {
            "sensorId": sensor_id,
            "type": type,
            "from": convert_datetime_to_str(from_temp),
            "to": convert_datetime_to_str(to_temp),
        }
        params = {k: v for k, v in params.items() if v is not None}
        coroutines.append(
            cast(
                "asyncio.Future[list[DataValueAvg]]",
                self._abase_request(f"avgData/{period}", params=params),
            )
        )
    return [
        data
        for data_value in await asyncio.gather(*coroutines)
        for data in data_value
    ]

acurrent() async

Get the last received valid data for each sensor in a city

Will not return sensor data older than 2 hours.

Returns:

Type Description
list[DataValueRaw]

a list of current data values

Source code in pulseeco/api/pulse_eco_api.py
async def acurrent(self) -> list[DataValueRaw]:
    """Get the last received valid data for each sensor in a city

    Will not return sensor data older than 2 hours.

    :return: a list of current data values
    """
    return cast(List[DataValueRaw], await self._abase_request("current"))

adata24h() async

Get 24h data for a city.

The data values are sorted ascending by their timestamp.

Returns:

Type Description
list[DataValueRaw]

a list of data values for the past 24 hours

Source code in pulseeco/api/pulse_eco_api.py
async def adata24h(self) -> list[DataValueRaw]:
    """Get 24h data for a city.

    The data values are sorted ascending by their timestamp.

    :return: a list of data values for the past 24 hours
    """
    return cast(List[DataValueRaw], await self._abase_request("data24h"))

adata_raw(from_, to, type=None, sensor_id=None) async

Get raw data for a city.

Parameters:

Name Type Description Default
from_ str | datetime

the start datetime of the data as a datetime object or an isoformat string

required
to str | datetime

the end datetime of the data as a datetime object or an isoformat string

required
type str | None

the data value type, defaults to None

None
sensor_id str | None

the unique ID of the sensor, defaults to None

None

Returns:

Type Description
list[DataValueRaw]

a list of data values

Source code in pulseeco/api/pulse_eco_api.py
async def adata_raw(
    self,
    from_: str | datetime.datetime,
    to: str | datetime.datetime,
    type: str | None = None,
    sensor_id: str | None = None,
) -> list[DataValueRaw]:
    """Get raw data for a city.

    :param from_: the start datetime of the data
        as a datetime object or an isoformat string
    :param to: the end datetime of the data
        as a datetime object or an isoformat string
    :param type: the data value type, defaults to None
    :param sensor_id: the unique ID of the sensor, defaults to None
    :return: a list of data values
    """
    if sensor_id is None and type is None:
        warnings.warn(
            "Warning! If you encounter an error, "
            "you should probably specify either sensor_id or type.",
            stacklevel=2,
        )
    coroutines: list[asyncio.Future[list[DataValueRaw]]] = []
    datetime_spans = split_datetime_span(from_, to, DATA_RAW_MAX_SPAN)
    for from_temp, to_temp in datetime_spans:
        params = {
            "sensorId": sensor_id,
            "type": type,
            "from": convert_datetime_to_str(from_temp),
            "to": convert_datetime_to_str(to_temp),
        }
        params = {k: v for k, v in params.items() if v is not None}
        coroutines.append(
            cast(
                "asyncio.Future[list[DataValueRaw]]",
                self._abase_request("dataRaw", params=params),
            )
        )
    return [
        data
        for data_value in await asyncio.gather(*coroutines)
        for data in data_value
    ]

aoverall() async

Get the current average data for all sensors per value for a city.

Example:
{
    'cityName': 'skopje',
    'values': {
        'no2': '22',
        'o3': '4',
        'pm25': '53',
        'pm10': '73',
        'temperature': '7',
        'humidity': '71',
        'pressure': '992',
        'noise_dba': '43'
    }
}

Returns:

Type Description
Overall

the overall data for the city

Source code in pulseeco/api/pulse_eco_api.py
async def aoverall(
    self,
) -> Overall:
    """Get the current average data for all sensors per value for a city.

    ## Example:

    ```python
    {
        'cityName': 'skopje',
        'values': {
            'no2': '22',
            'o3': '4',
            'pm25': '53',
            'pm10': '73',
            'temperature': '7',
            'humidity': '71',
            'pressure': '992',
            'noise_dba': '43'
        }
    }
    ```

    :return: the overall data for the city
    """
    return cast(Overall, await self._abase_request("overall"))

asensor(sensor_id) async

Get a sensor by it's ID

Parameters:

Name Type Description Default
sensor_id str

the unique ID of the sensor

required

Returns:

Type Description
Sensor

a sensor

Source code in pulseeco/api/pulse_eco_api.py
async def asensor(self, sensor_id: str) -> Sensor:
    """Get a sensor by it's ID

    :param sensor_id: the unique ID of the sensor
    :return: a sensor
    """
    return cast(Sensor, await self._abase_request(f"sensor/{sensor_id}"))

asensors() async

Get all sensors for a city.

Returns:

Type Description
list[Sensor]

a list of sensors

Source code in pulseeco/api/pulse_eco_api.py
async def asensors(self) -> list[Sensor]:
    """Get all sensors for a city.

    :return: a list of sensors
    """
    return cast(List[Sensor], await self._abase_request("sensor"))

avg_data(period, from_, to, type, sensor_id=None)

Get average data for a city.

Parameters:

Name Type Description Default
period str

the period of the average data (day, week, month)

required
from_ str | datetime

the start datetime of the data as a datetime object or an isoformat string

required
to str | datetime

the end datetime of the data as a datetime object or an isoformat string

required
type str

the data value type

required
sensor_id str | None

the unique ID of the sensor, defaults to None

None

Returns:

Type Description
list[DataValueAvg]

a list of average data values

Source code in pulseeco/api/pulse_eco_api.py
def avg_data(
    self,
    period: str,
    from_: str | datetime.datetime,
    to: str | datetime.datetime,
    type: str,
    sensor_id: str | None = None,
) -> list[DataValueAvg]:
    """Get average data for a city.

    :param period: the period of the average data (day, week, month)
    :param from_: the start datetime of the data
        as a datetime object or an isoformat string
    :param to: the end datetime of the data
        as a datetime object or an isoformat string
    :param type: the data value type
    :param sensor_id: the unique ID of the sensor, defaults to None
    :return: a list of average data values
    """
    if period not in {"day", "week", "month"}:
        warnings.warn(
            "Warning! Invalid value for period. "
            "Should be one of: day, week, month",
            stacklevel=2,
        )
    data: list[DataValueAvg] = []
    datetime_spans = split_datetime_span(from_, to, AVG_DATA_MAX_SPAN)
    for from_temp, to_temp in datetime_spans:
        params = {
            "sensorId": sensor_id,
            "type": type,
            "from": convert_datetime_to_str(from_temp),
            "to": convert_datetime_to_str(to_temp),
        }
        params = {k: v for k, v in params.items() if v is not None}
        data_value = cast(
            List[DataValueAvg],
            self._base_request(f"avgData/{period}", params=params),
        )
        data += data_value
    return data

current()

Get the last received valid data for each sensor in a city

Will not return sensor data older than 2 hours.

Returns:

Type Description
list[DataValueRaw]

a list of current data values

Source code in pulseeco/api/pulse_eco_api.py
def current(self) -> list[DataValueRaw]:
    """Get the last received valid data for each sensor in a city

    Will not return sensor data older than 2 hours.

    :return: a list of current data values
    """
    return cast(List[DataValueRaw], self._base_request("current"))

data24h()

Get 24h data for a city.

The data values are sorted ascending by their timestamp.

Returns:

Type Description
list[DataValueRaw]

a list of data values for the past 24 hours

Source code in pulseeco/api/pulse_eco_api.py
def data24h(self) -> list[DataValueRaw]:
    """Get 24h data for a city.

    The data values are sorted ascending by their timestamp.

    :return: a list of data values for the past 24 hours
    """
    return cast(List[DataValueRaw], self._base_request("data24h"))

data_raw(from_, to, type=None, sensor_id=None)

Get raw data for a city.

Parameters:

Name Type Description Default
from_ str | datetime

the start datetime of the data as a datetime object or an isoformat string

required
to str | datetime

the end datetime of the data as a datetime object or an isoformat string

required
type str | None

the data value type, defaults to None

None
sensor_id str | None

the unique ID of the sensor, defaults to None

None

Returns:

Type Description
list[DataValueRaw]

a list of data values

Source code in pulseeco/api/pulse_eco_api.py
def data_raw(
    self,
    from_: str | datetime.datetime,
    to: str | datetime.datetime,
    type: str | None = None,
    sensor_id: str | None = None,
) -> list[DataValueRaw]:
    """Get raw data for a city.

    :param from_: the start datetime of the data
        as a datetime object or an isoformat string
    :param to: the end datetime of the data
        as a datetime object or an isoformat string
    :param type: the data value type, defaults to None
    :param sensor_id: the unique ID of the sensor, defaults to None
    :return: a list of data values
    """
    if sensor_id is None and type is None:
        warnings.warn(
            "Warning! If you encounter an error, "
            "you should probably specify either sensor_id or type.",
            stacklevel=2,
        )
    data: list[DataValueRaw] = []
    datetime_spans = split_datetime_span(from_, to, DATA_RAW_MAX_SPAN)
    for from_temp, to_temp in datetime_spans:
        params = {
            "sensorId": sensor_id,
            "type": type,
            "from": convert_datetime_to_str(from_temp),
            "to": convert_datetime_to_str(to_temp),
        }
        params = {k: v for k, v in params.items() if v is not None}
        data_value = cast(
            List[DataValueRaw],
            self._base_request("dataRaw", params=params),
        )
        data += data_value
    return data

overall()

Get the current average data for all sensors per value for a city.

Example:
{
    'cityName': 'skopje',
    'values': {
        'no2': '22',
        'o3': '4',
        'pm25': '53',
        'pm10': '73',
        'temperature': '7',
        'humidity': '71',
        'pressure': '992',
        'noise_dba': '43'
    }
}

Returns:

Type Description
Overall

the overall data for the city

Source code in pulseeco/api/pulse_eco_api.py
def overall(
    self,
) -> Overall:
    """Get the current average data for all sensors per value for a city.

    ## Example:

    ```python
    {
        'cityName': 'skopje',
        'values': {
            'no2': '22',
            'o3': '4',
            'pm25': '53',
            'pm10': '73',
            'temperature': '7',
            'humidity': '71',
            'pressure': '992',
            'noise_dba': '43'
        }
    }
    ```

    :return: the overall data for the city
    """
    return cast(Overall, self._base_request("overall"))

sensor(sensor_id)

Get a sensor by it's ID

Parameters:

Name Type Description Default
sensor_id str

the unique ID of the sensor

required

Returns:

Type Description
Sensor

a sensor

Source code in pulseeco/api/pulse_eco_api.py
def sensor(self, sensor_id: str) -> Sensor:
    """Get a sensor by it's ID

    :param sensor_id: the unique ID of the sensor
    :return: a sensor
    """
    return cast(Sensor, self._base_request(f"sensor/{sensor_id}"))

sensors()

Get all sensors for a city.

Returns:

Type Description
list[Sensor]

a list of sensors

Source code in pulseeco/api/pulse_eco_api.py
def sensors(self) -> list[Sensor]:
    """Get all sensors for a city.

    :return: a list of sensors
    """
    return cast(List[Sensor], self._base_request("sensor"))