airbeld-api-sdk 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/CHANGELOG.md +30 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/PKG-INFO +234 -19
- airbeld_api_sdk-0.3.0/README.md +473 -0
- airbeld_api_sdk-0.3.0/examples/get_historical_readings.py +101 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/examples/get_latest_readings.py +1 -1
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/examples/quickstart.py +2 -9
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/pyproject.toml +1 -1
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/client.py +18 -19
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/models.py +0 -1
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/tests/test_client.py +10 -10
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/tests/test_models.py +2 -6
- airbeld_api_sdk-0.2.0/README.md +0 -258
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/.env.example +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/.gitignore +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/.ruff.toml +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/CONTRIBUTING.md +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/DEVELOPER.md +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/LICENSE +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/examples/.env.example +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/examples/login_and_list.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/mypy.ini +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/__init__.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/auth.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/exceptions.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/py.typed +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/src/airbeld/version.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/tests/test_auth.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/tests/test_exceptions.py +0 -0
- {airbeld_api_sdk-0.2.0 → airbeld_api_sdk-0.3.0}/uv.lock +0 -0
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2025-10-14
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- **Query parameter names updated** to match actual API specification:
|
|
10
|
+
- `start` → `start_date` (now accepts `YYYY-MM-DD` string format or `'today'`, not datetime objects)
|
|
11
|
+
- `end` → `end_date` (now accepts `YYYY-MM-DD` string format or `'today'`, not datetime objects)
|
|
12
|
+
- `sensors` → `sensor` (now accepts single sensor name string, not a list)
|
|
13
|
+
- `aggregate` → `period` (values: `'hour'` or `'day'`)
|
|
14
|
+
|
|
15
|
+
### Removed
|
|
16
|
+
|
|
17
|
+
- **Removed `device_uid` field** from `TelemetryBundle` model - the API response does not include device identifiers; the device is known from request context
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- New example `examples/get_historical_readings.py` demonstrating how to fetch multiple readings for a date range with hourly/daily aggregation
|
|
22
|
+
- Comprehensive documentation for historical readings in README
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Updated all examples to use correct API parameter names
|
|
27
|
+
- Updated API contract documentation to reflect actual Swagger specification
|
|
28
|
+
- Simplified `TelemetryBundle` to match actual API response structure (sensors only)
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Query parameters now match the actual API specification from Swagger
|
|
33
|
+
- Date format changed from ISO 8601 timestamps to `YYYY-MM-DD` strings as required by the API
|
|
34
|
+
|
|
5
35
|
## [0.2.0] - 2025-10-13
|
|
6
36
|
|
|
7
37
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: airbeld-api-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Async Python SDK for the Airbeld backend
|
|
5
5
|
Project-URL: Changelog, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/CHANGELOG.md
|
|
6
6
|
Project-URL: Documentation, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/README.md
|
|
@@ -76,34 +76,28 @@ python examples/quickstart.py
|
|
|
76
76
|
```python
|
|
77
77
|
import asyncio
|
|
78
78
|
import os
|
|
79
|
-
from datetime import datetime, timedelta, timezone
|
|
80
79
|
from airbeld import AirbeldClient
|
|
81
80
|
|
|
82
81
|
async def main():
|
|
83
82
|
# Initialize client (JWT token obtained outside SDK)
|
|
84
83
|
base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
|
|
85
84
|
token = os.environ["AIRBELD_API_TOKEN"]
|
|
86
|
-
|
|
85
|
+
|
|
87
86
|
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
88
87
|
# Get all devices
|
|
89
88
|
devices = await client.async_get_devices()
|
|
90
89
|
print(f"Found {len(devices)} devices")
|
|
91
|
-
|
|
90
|
+
|
|
92
91
|
if devices:
|
|
93
92
|
device = devices[0]
|
|
94
93
|
print(f"Device: {device.name} ({device.status})")
|
|
95
|
-
|
|
96
|
-
# Get
|
|
97
|
-
end = datetime.now(timezone.utc)
|
|
98
|
-
start = end - timedelta(hours=1)
|
|
99
|
-
|
|
94
|
+
|
|
95
|
+
# Get latest telemetry readings (no date range)
|
|
100
96
|
readings = await client.async_get_readings_by_date(
|
|
101
97
|
device_id=device.id,
|
|
102
|
-
|
|
103
|
-
end=end,
|
|
104
|
-
sensors=["temperature", "pm2p5"] # Optional sensor filter
|
|
98
|
+
sensor="temperature" # Optional: filter to single sensor
|
|
105
99
|
)
|
|
106
|
-
|
|
100
|
+
|
|
107
101
|
# Print latest temperature reading
|
|
108
102
|
if "temperature" in readings.sensors:
|
|
109
103
|
latest_temp = readings.get_latest_value("temperature")
|
|
@@ -115,7 +109,7 @@ if __name__ == "__main__":
|
|
|
115
109
|
|
|
116
110
|
**Note:** JWT token acquisition happens outside the SDK. The SDK only handles API requests with a ready token.
|
|
117
111
|
|
|
118
|
-
### Getting Latest Readings
|
|
112
|
+
### Getting Latest Readings
|
|
119
113
|
|
|
120
114
|
You can fetch the latest sensor readings without specifying a date range:
|
|
121
115
|
|
|
@@ -134,11 +128,8 @@ async def main():
|
|
|
134
128
|
if devices:
|
|
135
129
|
device = devices[0]
|
|
136
130
|
|
|
137
|
-
# Get latest readings without specifying
|
|
138
|
-
readings = await client.async_get_readings_by_date(
|
|
139
|
-
device_id=device.id,
|
|
140
|
-
sensors=["temperature", "pm2p5", "humidity"] # Optional filter
|
|
141
|
-
)
|
|
131
|
+
# Get latest readings without specifying start_date/end_date
|
|
132
|
+
readings = await client.async_get_readings_by_date(device_id=device.id)
|
|
142
133
|
|
|
143
134
|
# Display latest values
|
|
144
135
|
for sensor_name, metric in readings.sensors.items():
|
|
@@ -149,6 +140,230 @@ if __name__ == "__main__":
|
|
|
149
140
|
asyncio.run(main())
|
|
150
141
|
```
|
|
151
142
|
|
|
143
|
+
### Getting Historical Readings
|
|
144
|
+
|
|
145
|
+
Fetch sensor readings for a specific date range with hourly or daily aggregation:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import asyncio
|
|
149
|
+
import os
|
|
150
|
+
from airbeld import AirbeldClient
|
|
151
|
+
|
|
152
|
+
async def main():
|
|
153
|
+
base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
|
|
154
|
+
token = os.environ["AIRBELD_API_TOKEN"]
|
|
155
|
+
|
|
156
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
157
|
+
devices = await client.async_get_devices()
|
|
158
|
+
|
|
159
|
+
if devices:
|
|
160
|
+
device = devices[0]
|
|
161
|
+
|
|
162
|
+
# Get hourly readings for a specific date range
|
|
163
|
+
readings = await client.async_get_readings_by_date(
|
|
164
|
+
device_id=device.id,
|
|
165
|
+
start_date="2025-09-19", # Format: YYYY-MM-DD or 'today'
|
|
166
|
+
end_date="2025-09-19", # Same day = 24 hours of data
|
|
167
|
+
period="hour", # Aggregation: 'hour' or 'day'
|
|
168
|
+
sensor="temperature" # Optional: single sensor filter
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Access all temperature values
|
|
172
|
+
if "temperature" in readings.sensors:
|
|
173
|
+
temp_metric = readings.sensors["temperature"]
|
|
174
|
+
print(f"Temperature readings: {len(temp_metric.values)} values")
|
|
175
|
+
|
|
176
|
+
for reading in temp_metric.values:
|
|
177
|
+
print(f" {reading.timestamp}: {reading.value}°C")
|
|
178
|
+
|
|
179
|
+
if __name__ == "__main__":
|
|
180
|
+
asyncio.run(main())
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## API Reference
|
|
184
|
+
|
|
185
|
+
### Client Methods
|
|
186
|
+
|
|
187
|
+
#### `AirbeldClient(token, base_url, timeout)`
|
|
188
|
+
|
|
189
|
+
Initialize the Airbeld API client.
|
|
190
|
+
|
|
191
|
+
**Parameters:**
|
|
192
|
+
- `token` (str, required): JWT access token for authentication
|
|
193
|
+
- `base_url` (str, optional): API base URL. Default: `"https://api.airbeld.com"`
|
|
194
|
+
- `timeout` (float, optional): Request timeout in seconds. Default: `10.0`
|
|
195
|
+
|
|
196
|
+
**Usage:**
|
|
197
|
+
```python
|
|
198
|
+
async with AirbeldClient(token=token, base_url=base_url) as client:
|
|
199
|
+
# Use client...
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
#### `async_get_devices()`
|
|
205
|
+
|
|
206
|
+
Get list of all devices.
|
|
207
|
+
|
|
208
|
+
**Parameters:** None
|
|
209
|
+
|
|
210
|
+
**Returns:** `list[DeviceSummary]` - List of device objects
|
|
211
|
+
|
|
212
|
+
**Raises:**
|
|
213
|
+
- `AuthError`: Authentication failed (401/403)
|
|
214
|
+
- `ApiError`: Other API errors (4xx/5xx)
|
|
215
|
+
- `NetworkError`: Network connectivity issues
|
|
216
|
+
|
|
217
|
+
**Example:**
|
|
218
|
+
```python
|
|
219
|
+
devices = await client.async_get_devices()
|
|
220
|
+
for device in devices:
|
|
221
|
+
print(f"{device.name} - {device.status}")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
#### `async_get_readings_by_date(device_id, start_date, end_date, sensor, period)`
|
|
227
|
+
|
|
228
|
+
Get telemetry readings for a device.
|
|
229
|
+
|
|
230
|
+
**Parameters:**
|
|
231
|
+
- `device_id` (int, required): Device ID
|
|
232
|
+
- `start_date` (str, optional): Start date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
233
|
+
- `end_date` (str, optional): End date in `YYYY-MM-DD` format or `'today'`. If omitted, returns latest data.
|
|
234
|
+
- `sensor` (str, optional): Single sensor name to filter (e.g., `"temperature"`, `"pm2p5"`). If omitted, returns all sensors.
|
|
235
|
+
- `period` (str, optional): Data aggregation period. Values: `"hour"` or `"day"`.
|
|
236
|
+
|
|
237
|
+
**Returns:** `TelemetryBundle` - Object containing sensor readings
|
|
238
|
+
|
|
239
|
+
**Raises:**
|
|
240
|
+
- `AuthError`: Authentication failed (401/403)
|
|
241
|
+
- `ApiError`: API errors including 404 (device not found), 413 (range too large)
|
|
242
|
+
- `RateLimitError`: Rate limit exceeded (429)
|
|
243
|
+
- `NetworkError`: Network connectivity issues
|
|
244
|
+
|
|
245
|
+
**Examples:**
|
|
246
|
+
```python
|
|
247
|
+
# Get latest readings (no date range)
|
|
248
|
+
readings = await client.async_get_readings_by_date(device_id=123)
|
|
249
|
+
|
|
250
|
+
# Get historical readings with date range
|
|
251
|
+
readings = await client.async_get_readings_by_date(
|
|
252
|
+
device_id=123,
|
|
253
|
+
start_date="2025-09-19",
|
|
254
|
+
end_date="2025-09-19",
|
|
255
|
+
period="hour"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# Filter to single sensor
|
|
259
|
+
readings = await client.async_get_readings_by_date(
|
|
260
|
+
device_id=123,
|
|
261
|
+
sensor="temperature"
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
#### `set_token(new_token)`
|
|
268
|
+
|
|
269
|
+
Update the authorization token at runtime.
|
|
270
|
+
|
|
271
|
+
**Parameters:**
|
|
272
|
+
- `new_token` (str, required): New JWT access token
|
|
273
|
+
|
|
274
|
+
**Returns:** None
|
|
275
|
+
|
|
276
|
+
**Example:**
|
|
277
|
+
```python
|
|
278
|
+
client.set_token(refreshed_token)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Authentication Functions
|
|
282
|
+
|
|
283
|
+
#### `async_login(base_url, email, password, timeout)`
|
|
284
|
+
|
|
285
|
+
Authenticate with email and password to obtain JWT tokens.
|
|
286
|
+
|
|
287
|
+
**Parameters:**
|
|
288
|
+
- `base_url` (str, required): API base URL
|
|
289
|
+
- `email` (str, required): User email address
|
|
290
|
+
- `password` (str, required): User password
|
|
291
|
+
- `timeout` (float, optional): Request timeout in seconds. Default: `10.0`
|
|
292
|
+
|
|
293
|
+
**Returns:** `TokenSet` - Object containing access token, refresh token, expires_in, and token_type
|
|
294
|
+
|
|
295
|
+
**Raises:**
|
|
296
|
+
- `AuthError`: Invalid credentials (401)
|
|
297
|
+
- `RateLimitError`: Rate limit exceeded (429)
|
|
298
|
+
- `ApiError`: Other API errors (4xx/5xx)
|
|
299
|
+
- `NetworkError`: Network connectivity issues
|
|
300
|
+
|
|
301
|
+
**Example:**
|
|
302
|
+
```python
|
|
303
|
+
from airbeld import async_login
|
|
304
|
+
|
|
305
|
+
token_set = await async_login(
|
|
306
|
+
base_url="https://api.airbeld.com",
|
|
307
|
+
email="user@example.com",
|
|
308
|
+
password="password"
|
|
309
|
+
)
|
|
310
|
+
print(f"Access token: {token_set.access_token}")
|
|
311
|
+
print(f"Expires in: {token_set.expires_in} seconds")
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Data Models
|
|
315
|
+
|
|
316
|
+
#### `DeviceSummary`
|
|
317
|
+
|
|
318
|
+
Device information object.
|
|
319
|
+
|
|
320
|
+
**Attributes:**
|
|
321
|
+
- `uid` (str): Unique device identifier
|
|
322
|
+
- `id` (int): Device ID
|
|
323
|
+
- `name` (str): Device name
|
|
324
|
+
- `display_name` (str | None): Custom display name
|
|
325
|
+
- `description` (str): Device description
|
|
326
|
+
- `type` (str | None): Device type
|
|
327
|
+
- `is_locked` (bool): Whether device is locked
|
|
328
|
+
- `status` (str): Device status - `"online"` or `"offline"`
|
|
329
|
+
- `sector` (str | None): Sector name
|
|
330
|
+
- `sector_id` (int | None): Sector ID
|
|
331
|
+
- `location` (str | None): Location name
|
|
332
|
+
- `location_id` (int | None): Location ID
|
|
333
|
+
- `timezone` (str): IANA timezone
|
|
334
|
+
|
|
335
|
+
#### `TelemetryBundle`
|
|
336
|
+
|
|
337
|
+
Container for sensor telemetry data.
|
|
338
|
+
|
|
339
|
+
**Attributes:**
|
|
340
|
+
- `sensors` (dict[str, TelemetryMetric]): Dictionary of sensor metrics by sensor name
|
|
341
|
+
|
|
342
|
+
**Methods:**
|
|
343
|
+
- `get_latest_value(metric_name: str) -> float | None`: Get the latest value for a specific sensor
|
|
344
|
+
- `pm2_5` (property): Shortcut to access PM 2.5 metric (returns `TelemetryMetric | None`)
|
|
345
|
+
|
|
346
|
+
#### `TelemetryMetric`
|
|
347
|
+
|
|
348
|
+
Individual sensor metric with metadata and values.
|
|
349
|
+
|
|
350
|
+
**Attributes:**
|
|
351
|
+
- `name` (str): Sensor name
|
|
352
|
+
- `display_name` (str | None): Display name
|
|
353
|
+
- `unit` (str): Measurement unit
|
|
354
|
+
- `description` (str | None): Sensor description
|
|
355
|
+
- `values` (list[TelemetryValue]): List of readings
|
|
356
|
+
|
|
357
|
+
#### `TelemetryValue`
|
|
358
|
+
|
|
359
|
+
Single sensor reading.
|
|
360
|
+
|
|
361
|
+
**Attributes:**
|
|
362
|
+
- `timestamp` (datetime): Reading timestamp
|
|
363
|
+
- `value` (float | None): Measured value
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
152
367
|
## Authentication Options
|
|
153
368
|
|
|
154
369
|
The SDK supports two authentication paths depending on your use case:
|