airbeld-api-sdk 0.1.1__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.
@@ -0,0 +1,12 @@
1
+ # API base URL (not secret, can be changed for dev/staging/prod)
2
+ AIRBELD_API_BASE=https://api.airbeld.com
3
+
4
+ # API token (JWT). Leave empty here.
5
+ # Developers should obtain a token from /api/v1/auth/token/
6
+ # and export it locally, never commit real tokens to git.
7
+ AIRBELD_API_TOKEN=REPLACE_WITH_REAL_JWT
8
+
9
+ # Authentication (for standalone examples only)
10
+ # Do not use these credentials with Home Assistant integration
11
+ AIRBELD_USER_EMAIL=
12
+ AIRBELD_USER_PASSWORD=
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: Bug report
3
+ about: Help us fix an issue
4
+ ---
5
+
6
+ **Describe the bug**
7
+ A clear and concise description of what the bug is.
8
+
9
+ **To Reproduce**
10
+ Steps/code to reproduce the behavior.
11
+
12
+ **Expected behavior**
13
+ What you expected to happen.
14
+
15
+ **Environment (please complete the following):**
16
+ - OS:
17
+ - Python:
18
+ - SDK version:
@@ -0,0 +1,29 @@
1
+ name: ci
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - name: Install uv
20
+ run: curl -LsSf https://astral.sh/uv/install.sh | sh
21
+ - name: Install project (dev)
22
+ run: |
23
+ ~/.local/bin/uv pip install -e ".[dev]"
24
+ - name: Lint, type-check, test
25
+ run: |
26
+ ~/.local/bin/uv run ruff check .
27
+ ~/.local/bin/uv run ruff format --check .
28
+ ~/.local/bin/uv run mypy src
29
+ ~/.local/bin/uv run pytest -q
@@ -0,0 +1,38 @@
1
+ # Byte-compiled / optimized files
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+
6
+ # Distribution / packaging
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Environment variables
17
+ .env
18
+ *.local.json
19
+
20
+ # Testing and coverage
21
+ .coverage
22
+ .pytest_cache/
23
+
24
+ # Type checking and linting
25
+ .mypy_cache/
26
+ .ruff_cache/
27
+
28
+ # Claude Code (development only)
29
+ .claude/
30
+ .mcp.json
31
+ CLAUDE.md
32
+
33
+ # IDE and OS
34
+ .DS_Store
35
+ .vscode/
36
+ .idea/
37
+ *.swp
38
+ *.swo
@@ -0,0 +1,29 @@
1
+ # Ruff configuration for airbeld-api-sdk
2
+ target-version = "py310"
3
+ line-length = 100
4
+
5
+ [lint]
6
+ select = [
7
+ "E", # pycodestyle errors
8
+ "W", # pycodestyle warnings
9
+ "F", # pyflakes
10
+ "I", # isort
11
+ "B", # flake8-bugbear
12
+ "C4", # flake8-comprehensions
13
+ "UP", # pyupgrade
14
+ "RUF", # ruff-specific rules
15
+ ]
16
+ ignore = [
17
+ "E501", # line too long (handled by line-length setting)
18
+ ]
19
+
20
+ [format]
21
+ quote-style = "double"
22
+ indent-style = "space"
23
+ line-ending = "auto"
24
+
25
+ [lint.per-file-ignores]
26
+ "tests/*" = ["B011"] # allow assert False in tests
27
+
28
+ [lint.isort]
29
+ known-first-party = ["airbeld"]
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0] - 2025-10-12
6
+
7
+ ### Added
8
+ - Initial public release of airbeld-api-sdk
9
+ - Async HTTP client (`AirbeldClient`) for Airbeld API
10
+ - Device management: list devices with full metadata (name, status, location, timezone)
11
+ - Telemetry data: fetch readings by date range with optional sensor filtering
12
+ - Authentication: JWT token support with `async_login()` helper for email/password
13
+ - Token management: `set_token()` method for runtime token refresh
14
+ - Type safety: full type hints with `py.typed` marker for mypy support
15
+ - Error handling: structured exceptions (`AuthError`, `RateLimitError`, `NetworkError`, `ApiError`)
16
+ - Retry logic: automatic retries with exponential backoff and jitter
17
+ - Rate limit handling: respects `Retry-After` headers on 429 responses
18
+ - Pydantic models: automatic camelCase ↔ snake_case mapping for API compatibility
19
+ - Comprehensive test suite using pytest and respx for HTTP mocking
20
+ - CI/CD: GitHub Actions workflow for lint, type-check, and tests on Python 3.10-3.12
21
+ - Examples: quickstart and standalone login examples
22
+ - Documentation: README with usage examples, API contract, developer guide
@@ -0,0 +1,36 @@
1
+ # Contributing Guide
2
+
3
+ Thanks for your interest in contributing!
4
+
5
+ ## Overview
6
+ All contributions must pass the quality gates and follow the coding rules below.
7
+
8
+ ## Quality Gates (must pass locally)
9
+ - `ruff check .`
10
+ - `ruff format --check .`
11
+ - `mypy src`
12
+ - `pytest -q`
13
+
14
+ ## Coding Rules
15
+ - Python ≥ 3.10.
16
+ - Async-only networking (httpx.AsyncClient).
17
+ - Default timeouts (10s) and retries (3, exponential backoff).
18
+ - Strict typing; concise docstrings; **no secrets in logs**.
19
+ - Keep diffs minimal; avoid touching unrelated files.
20
+
21
+ ## Public API Stability
22
+ - Do not introduce breaking changes without a migration note and prior discussion.
23
+ - If public API changes, update `README.md` usage and add a `CHANGELOG.md` entry.
24
+
25
+ ## Documentation
26
+ - `README.md` is for users; keep it clear and up to date.
27
+ - Developer details live in [DEVELOPER.md](DEVELOPER.md).
28
+ - API contract/spec for endpoints and payloads lives in [docs/api-contract.md](docs/api-contract.md).
29
+
30
+ ## Development Workflow
31
+ 1. Propose a plan or discuss the change in an issue first
32
+ 2. Implement changes with minimal diffs (one feature/file at a time)
33
+ 3. Add focused tests (happy path + error cases)
34
+ 4. Ensure all quality gates pass locally
35
+ 5. Write a concise commit message following Conventional Commits format
36
+ 6. Open a PR with a clear description of the changes
@@ -0,0 +1,189 @@
1
+ # Developer Guide
2
+
3
+ ## Local Environment Setup
4
+
5
+ ### Requirements
6
+ - Python 3.10 or higher
7
+ - Recommended: `uv` for fast dependency management
8
+ - Alternative: `pip` with virtual environments
9
+
10
+ ### Installation
11
+
12
+ **Using uv (recommended):**
13
+ ```bash
14
+ uv sync
15
+ ```
16
+
17
+ **Using pip:**
18
+ ```bash
19
+ python -m venv .venv
20
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
21
+ pip install -e ".[dev]"
22
+ ```
23
+
24
+ ## Development Tools
25
+
26
+ ### Quality Gates
27
+ All changes must pass these checks before committing:
28
+
29
+ ```bash
30
+ # Lint check
31
+ uv run ruff check .
32
+
33
+ # Format check
34
+ uv run ruff format --check .
35
+
36
+ # Type check
37
+ uv run mypy src
38
+
39
+ # Run tests
40
+ uv run pytest -q
41
+ ```
42
+
43
+ **Or with pip:**
44
+ ```bash
45
+ ruff check .
46
+ ruff format --check .
47
+ mypy src
48
+ pytest -q
49
+ ```
50
+
51
+ ### Running Tests
52
+ ```bash
53
+ # Run all tests
54
+ uv run pytest
55
+
56
+ # Run with coverage
57
+ uv run pytest --cov=airbeld --cov-report=html
58
+
59
+ # Run specific test file
60
+ uv run pytest tests/test_client.py
61
+
62
+ # Run with verbose output
63
+ uv run pytest -v
64
+ ```
65
+
66
+ ### Building the Package
67
+ ```bash
68
+ # Build distribution files
69
+ uv build
70
+
71
+ # Check the built package
72
+ twine check dist/*
73
+ ```
74
+
75
+ ## API Contract
76
+
77
+ The `docs/api-contract.md` file is the **source of truth** for backend endpoints, authentication, and payload schemas. Always consult it when implementing new features or fixing bugs.
78
+
79
+ ## Public API Stability
80
+
81
+ - **Breaking changes require major version bumps**
82
+ - Before introducing breaking changes:
83
+ 1. Open an issue for discussion
84
+ 2. Add migration notes
85
+ 3. Update `README.md` with usage changes
86
+ 4. Add entry to `CHANGELOG.md`
87
+
88
+ ## Documentation
89
+
90
+ - **README.md**: User-facing documentation with examples
91
+ - **docs/api-contract.md**: Technical API specification
92
+ - **docs/home-assistant-auth.md**: Home Assistant integration details
93
+ - **CHANGELOG.md**: Version history and changes
94
+
95
+ Keep examples minimal, runnable, and well-tested.
96
+
97
+ ## Git Workflow
98
+
99
+ ### Branch Naming
100
+ - Features: `feat/description`
101
+ - Bug fixes: `fix/description`
102
+ - Chores: `chore/description`
103
+
104
+ ### Commit Messages
105
+ Follow [Conventional Commits](https://www.conventionalcommits.org/):
106
+
107
+ ```
108
+ feat: add support for hourly aggregation
109
+ fix: handle missing Retry-After header correctly
110
+ chore: update dependencies
111
+ docs: improve authentication examples
112
+ test: add coverage for rate limiting
113
+ ```
114
+
115
+ ### Pull Requests
116
+ - Keep PRs small and focused
117
+ - Include test coverage for new features
118
+ - Ensure all quality gates pass
119
+ - Provide clear description of changes
120
+ - Link related issues
121
+
122
+ ## Environment Variables
123
+
124
+ For local development and testing:
125
+
126
+ ```bash
127
+ # Create .env file (never commit this!)
128
+ cp .env.example .env
129
+
130
+ # Edit with your test credentials
131
+ AIRBELD_API_BASE=https://api.airbeld.com
132
+ AIRBELD_API_TOKEN=your-jwt-token
133
+ AIRBELD_USER_EMAIL=your-email@example.com
134
+ AIRBELD_USER_PASSWORD=your-password
135
+ ```
136
+
137
+ **Never commit secrets to version control.**
138
+
139
+ ## Testing Strategy
140
+
141
+ - Use `pytest` for all tests
142
+ - Mock HTTP requests with `unittest.mock` or `respx`
143
+ - No live API requests in tests
144
+ - Cover both success and error cases
145
+ - Test edge cases (empty responses, missing fields, etc.)
146
+
147
+ Example test structure:
148
+ ```python
149
+ @pytest.mark.asyncio
150
+ async def test_feature_name():
151
+ """Test description."""
152
+ # Arrange: Set up mocks and test data
153
+ # Act: Call the function
154
+ # Assert: Verify the results
155
+ ```
156
+
157
+ ## Release Process
158
+
159
+ 1. Update version in `pyproject.toml`
160
+ 2. Update `CHANGELOG.md` with changes
161
+ 3. Commit: `chore: prepare release X.Y.Z`
162
+ 4. Create git tag: `git tag vX.Y.Z`
163
+ 5. Push: `git push && git push --tags`
164
+ 6. Build: `uv build`
165
+ 7. Publish to PyPI: `twine upload dist/*`
166
+
167
+ ## Troubleshooting
168
+
169
+ ### Common Issues
170
+
171
+ **Import errors after installation:**
172
+ ```bash
173
+ # Reinstall in editable mode
174
+ pip install -e ".[dev]"
175
+ ```
176
+
177
+ **Type checking failures:**
178
+ ```bash
179
+ # Clear mypy cache
180
+ rm -rf .mypy_cache
181
+ mypy src
182
+ ```
183
+
184
+ **Tests failing:**
185
+ ```bash
186
+ # Clear pytest cache
187
+ rm -rf .pytest_cache
188
+ pytest -v
189
+ ```
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Airbeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice (including the next
13
+ paragraph) shall be included in all copies or substantial portions of the
14
+ Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
+ IN THE SOFTWARE.
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: airbeld-api-sdk
3
+ Version: 0.1.1
4
+ Summary: Async Python SDK for the Airbeld backend
5
+ Project-URL: Changelog, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/CHANGELOG.md
6
+ Project-URL: Documentation, https://github.com/Embio-Diagnostics/airbeld-api-sdk/blob/main/README.md
7
+ Project-URL: Homepage, https://github.com/Embio-Diagnostics/airbeld-api-sdk
8
+ Project-URL: Issues, https://github.com/Embio-Diagnostics/airbeld-api-sdk/issues
9
+ Project-URL: Repository, https://github.com/Embio-Diagnostics/airbeld-api-sdk
10
+ Author-email: Embio Diagnostics Ltd <l.dougiakis@embiodiagnostics.eu>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: air-quality,airbeld,home-assistant
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: httpx>=0.28.1
20
+ Requires-Dist: pydantic>=2.11.7
21
+ Requires-Dist: tenacity>=9.1.2
22
+ Provides-Extra: dev
23
+ Requires-Dist: httpx>=0.27; extra == 'dev'
24
+ Requires-Dist: mypy>=1.10; extra == 'dev'
25
+ Requires-Dist: pydantic>=2.7; extra == 'dev'
26
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
27
+ Requires-Dist: pytest>=8; extra == 'dev'
28
+ Requires-Dist: ruff>=0.5; extra == 'dev'
29
+ Requires-Dist: tenacity>=8.2; extra == 'dev'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Airbeld Python SDK
33
+
34
+ Async Python SDK for the Airbeld API, providing access to air quality devices and telemetry data.
35
+
36
+ > If you want to **contribute**, read [CONTRIBUTING](CONTRIBUTING.md) and [DEVELOPER](DEVELOPER.md).
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ # Using pip
44
+ pip install airbeld-api-sdk
45
+
46
+ # Using uv (recommended)
47
+ uv add airbeld-api-sdk
48
+ ```
49
+
50
+ ## Examples
51
+
52
+ ### Environment Variables
53
+
54
+ Set these environment variables for the examples:
55
+
56
+ - `AIRBELD_API_BASE`: API base URL (default: `https://api.airbeld.com`)
57
+ - `AIRBELD_API_TOKEN`: JWT access token for authentication
58
+
59
+ ### Quickstart Example
60
+
61
+ ```python
62
+ import asyncio
63
+ import os
64
+ from datetime import datetime, timedelta, timezone
65
+ from airbeld import AirbeldClient
66
+
67
+ async def main():
68
+ # Initialize client (JWT token obtained outside SDK)
69
+ base_url = os.environ.get("AIRBELD_API_BASE", "https://api.airbeld.com")
70
+ token = os.environ["AIRBELD_API_TOKEN"]
71
+
72
+ async with AirbeldClient(token=token, base_url=base_url) as client:
73
+ # Get all devices
74
+ devices = await client.async_get_devices()
75
+ print(f"Found {len(devices)} devices")
76
+
77
+ if devices:
78
+ device = devices[0]
79
+ print(f"Device: {device.name} ({device.status})")
80
+
81
+ # Get recent telemetry readings
82
+ end = datetime.now(timezone.utc)
83
+ start = end - timedelta(hours=1)
84
+
85
+ readings = await client.async_get_readings_by_date(
86
+ device_id=device.id,
87
+ start=start,
88
+ end=end,
89
+ sensors=["temperature", "pm2p5"] # Optional sensor filter
90
+ )
91
+
92
+ # Print latest temperature reading
93
+ if "temperature" in readings.sensors:
94
+ latest_temp = readings.get_latest_value("temperature")
95
+ print(f"Latest temperature: {latest_temp}°C")
96
+
97
+ if __name__ == "__main__":
98
+ asyncio.run(main())
99
+ ```
100
+
101
+ **Note:** JWT token acquisition happens outside the SDK. The SDK only handles API requests with a ready token.
102
+
103
+ ## Authentication Options
104
+
105
+ The SDK supports two authentication paths depending on your use case:
106
+
107
+ ### Home Assistant Integration
108
+
109
+ For Home Assistant users, authentication is handled by the integration:
110
+
111
+ - Home Assistant performs OAuth2 flow automatically
112
+ - SDK receives a ready JWT token from the integration
113
+ - See [docs/home-assistant-auth.md](docs/home-assistant-auth.md) for details
114
+
115
+ ### Standalone Applications (CLI, Scripts, etc.)
116
+
117
+ For standalone applications, use the built-in authentication:
118
+
119
+ ```python
120
+ import asyncio
121
+ import os
122
+ from airbeld import async_login, AirbeldClient
123
+
124
+ async def main():
125
+ # Authenticate with email/password
126
+ token_set = await async_login(
127
+ base_url="https://api.airbeld.com",
128
+ email=os.environ["AIRBELD_USER_EMAIL"],
129
+ password=os.environ["AIRBELD_USER_PASSWORD"]
130
+ )
131
+
132
+ # Create client with access token
133
+ async with AirbeldClient(token=token_set.access_token) as client:
134
+ # List devices
135
+ devices = await client.async_get_devices()
136
+ print(f"Found {len(devices)} devices:")
137
+
138
+ for device in devices:
139
+ print(f" - {device.name} ({device.status})")
140
+
141
+ if __name__ == "__main__":
142
+ asyncio.run(main())
143
+ ```
144
+
145
+ **⚠️ Security Warning:** Never commit real credentials or tokens to version control. Use environment variables or secure secret storage systems.
146
+
147
+ ### Token Management
148
+
149
+ For applications requiring token refresh or runtime token updates:
150
+
151
+ ```python
152
+ # Update token at runtime
153
+ client.set_token(new_token)
154
+
155
+ # Or use refresh token (if implemented)
156
+ new_token_set = await async_login(...)
157
+ client.set_token(new_token_set.access_token)
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Development
163
+
164
+ ### Installation
165
+
166
+ Using uv (recommended):
167
+ ```bash
168
+ # Clone the repository
169
+ git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
170
+ cd airbeld-api-sdk
171
+
172
+ # Create virtual environment and install dependencies
173
+ uv sync
174
+ ```
175
+
176
+ Using pip:
177
+ ```bash
178
+ # Clone the repository
179
+ git clone https://github.com/Embio-Diagnostics/airbeld-api-sdk.git
180
+ cd airbeld-api-sdk
181
+
182
+ # Create and activate virtual environment
183
+ python -m venv .venv
184
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
185
+
186
+ # Install package with dev dependencies
187
+ pip install -e ".[dev]"
188
+ ```
189
+
190
+ ### Running Tests
191
+
192
+ ```bash
193
+ # Using uv
194
+ uv run pytest
195
+
196
+ # Or with pip
197
+ pytest
198
+ ```
199
+
200
+ ### Linting and Formatting
201
+
202
+ ```bash
203
+ # Check code style
204
+ uv run ruff check .
205
+
206
+ # Format code
207
+ uv run ruff format .
208
+
209
+ # Or with pip
210
+ ruff check .
211
+ ruff format .
212
+ ```
213
+
214
+ ### Type Checking
215
+
216
+ ```bash
217
+ # Using uv
218
+ uv run mypy src
219
+
220
+ # Or with pip
221
+ mypy src
222
+ ```
223
+
224
+ ### Building the Package
225
+
226
+ ```bash
227
+ # Using uv
228
+ uv build
229
+
230
+ # Or with pip
231
+ python -m build
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Resources
237
+
238
+ - **Contributing:** See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines
239
+ - **Changelog:** See [CHANGELOG.md](CHANGELOG.md) for version history
240
+ - **License:** This project is licensed under the MIT License - see [LICENSE](LICENSE) file for details