qnap-client 1.0.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.
@@ -0,0 +1,21 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ .Python
6
+ build/
7
+ dist/
8
+ *.egg-info/
9
+ .eggs/
10
+ .env
11
+ .venv
12
+ env/
13
+ venv/
14
+ .pytest_cache/
15
+ .mypy_cache/
16
+ .ruff_cache/
17
+ *.egg
18
+ pip-wheel-metadata/
19
+ share/python-wheels/
20
+ *.manifest
21
+ *.spec
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to `qnap-client` will be documented here.
4
+
5
+ ## [1.0.0] - 2026-05-05
6
+
7
+ Initial release. Full async rewrite replacing `python-qnapstats`.
8
+
9
+ ### Added
10
+ - `QnapClient` — fully async aiohttp-based client
11
+ - `ContainerStationClient` — Docker/LXC container management via Container Station API
12
+ - Typed dataclass models for all API responses
13
+ - Full exception hierarchy (`QnapError`, `QnapAuthError`, `QnapConnectionError`, `QnapTimeoutError`, `QnapAPIError`)
14
+ - `get_all()` — fetches all NAS data in parallel with `asyncio.gather`
15
+ - Fan speed support (`get_fans()`)
16
+ - External drive support (`get_external_drives()`)
17
+ - Graceful handling of missing/unexpected API response fields
18
+ - Proper handling of `newVersion` key absence in firmware update API
19
+ - Graceful skip of unrecognized network interface keys (fixes eth_status5 crash on QNAP-473e)
20
+ - Drive temperature returns `None` instead of `0` when data unavailable
21
+ - Session auto-retry on 401 for Container Station v1 API
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 disforw
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 shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: qnap-client
3
+ Version: 1.0.0
4
+ Summary: Async Python client for QNAP NAS — replaces python-qnapstats
5
+ Project-URL: Homepage, https://github.com/disforw/python-qnap
6
+ Project-URL: Repository, https://github.com/disforw/python-qnap
7
+ Project-URL: Issues, https://github.com/disforw/python-qnap/issues
8
+ Project-URL: Changelog, https://github.com/disforw/python-qnap/blob/main/CHANGELOG.md
9
+ Author-email: disforw <disforw@users.noreply.github.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: aiohttp,async,container-station,homeassistant,nas,qnap
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Home Automation
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: aiohttp>=3.9.0
22
+ Requires-Dist: xmltodict>=0.13.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: aioresponses>=0.7; extra == 'dev'
25
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # QNAP NAS Integration for Home Assistant
30
+
31
+ [![PyPI version](https://img.shields.io/pypi/v/qnap-client.svg)](https://pypi.org/project/qnap-client/)
32
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
33
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
34
+
35
+ Async Python client for QNAP NAS. Replaces the unmaintained `python-qnapstats` with a fully async, `aiohttp`-based library with typed models, proper exception handling, Container Station support, and graceful handling of unexpected API responses.
36
+
37
+ ## Why This Exists
38
+
39
+ `python-qnapstats` hasn't had a meaningful update in years. Fan sensor support and external drive support were added to the source repo but never published to PyPI. The library is synchronous, has no typed return values, and crashes on certain NAS models due to missing key handling.
40
+
41
+ This library fixes all of that.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install qnap-client
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```python
52
+ import asyncio
53
+ from qnap_client import QnapClient
54
+
55
+ async def main():
56
+ async with QnapClient("192.168.1.100", 8080, "admin", "password") as client:
57
+ data = await client.get_all()
58
+ print(f"NAS: {data.system_info.name} ({data.system_info.model})")
59
+ print(f"CPU: {data.system_info.cpu_usage_percent:.1f}%")
60
+ print(f"Health: {data.system_health.status}")
61
+ for vol in data.volumes:
62
+ used_pct = vol.used_bytes / vol.total_bytes * 100
63
+ print(f"Volume {vol.name}: {used_pct:.1f}% used")
64
+ if data.firmware_update.latest_version:
65
+ print(f"Firmware update available: {data.firmware_update.latest_version}")
66
+
67
+ asyncio.run(main())
68
+ ```
69
+
70
+ ## API Reference
71
+
72
+ ### `QnapClient`
73
+
74
+ ```python
75
+ QnapClient(
76
+ host: str,
77
+ port: int,
78
+ username: str,
79
+ password: str,
80
+ *,
81
+ ssl: bool = False,
82
+ verify_ssl: bool = True,
83
+ timeout: int = 10,
84
+ session: aiohttp.ClientSession | None = None,
85
+ )
86
+ ```
87
+
88
+ | Method | Returns | Description |
89
+ |---|---|---|
90
+ | `login()` | `None` | Authenticate and store session ID |
91
+ | `logout()` | `None` | Log out and clear session |
92
+ | `get_system_info()` | `SystemInfo` | CPU, memory, firmware version, uptime |
93
+ | `get_system_health()` | `SystemHealth` | Overall health status string |
94
+ | `get_network_interfaces()` | `list[NetworkInterface]` | Per-interface RX/TX rates |
95
+ | `get_drive_health()` | `list[DriveHealth]` | S.M.A.R.T. status + temperature per drive |
96
+ | `get_volumes()` | `list[VolumeStats]` | Storage volume usage |
97
+ | `get_firmware_update()` | `FirmwareUpdate` | Current + latest firmware version |
98
+ | `get_fans()` | `list[FanStatus]` | Fan speed RPM (empty list if unsupported) |
99
+ | `get_external_drives()` | `list[ExternalDrive]` | External USB/eSATA drives |
100
+ | `get_all()` | `NasData` | All of the above in parallel |
101
+
102
+ ### `ContainerStationClient`
103
+
104
+ ```python
105
+ from qnap_client import ContainerStationClient
106
+
107
+ async with QnapClient(...) as client:
108
+ cs = ContainerStationClient(client)
109
+ containers = await cs.get_containers()
110
+ await cs.stop_container(containers[0].id)
111
+ ```
112
+
113
+ | Method | Returns | Description |
114
+ |---|---|---|
115
+ | `get_containers()` | `list[Container]` | All containers with id, name, status, image, type |
116
+ | `start_container(id, type)` | `None` | Start a container |
117
+ | `stop_container(id, type)` | `None` | Stop a container |
118
+ | `restart_container(id, type)` | `None` | Restart a container |
119
+ | `container_action(id, type, action)` | `None` | Generic action (start/stop/restart) |
120
+
121
+ ### Models
122
+
123
+ | Model | Fields |
124
+ |---|---|
125
+ | `SystemInfo` | `name`, `model`, `serial_number`, `firmware_version`, `uptime_seconds`, `cpu_usage_percent`, `memory_total_mb`, `memory_free_mb`, `memory_used_mb` |
126
+ | `SystemHealth` | `status` |
127
+ | `NetworkInterface` | `name`, `mac`, `ip`, `rx_bytes_per_sec`, `tx_bytes_per_sec` |
128
+ | `DriveHealth` | `drive_number`, `model`, `health`, `temperature` |
129
+ | `VolumeStats` | `name`, `total_bytes`, `used_bytes`, `free_bytes`, `status` |
130
+ | `FirmwareUpdate` | `current_version`, `latest_version` (None = up to date) |
131
+ | `FanStatus` | `fan_number`, `speed_rpm` |
132
+ | `ExternalDrive` | `name`, `total_bytes`, `used_bytes`, `free_bytes` |
133
+ | `Container` | `id`, `name`, `status`, `image`, `type` |
134
+ | `NasData` | All of the above combined |
135
+
136
+ ### Exceptions
137
+
138
+ | Exception | When |
139
+ |---|---|
140
+ | `QnapError` | Base exception |
141
+ | `QnapAuthError` | Bad credentials or session expired |
142
+ | `QnapConnectionError` | NAS unreachable |
143
+ | `QnapTimeoutError` | Request timed out |
144
+ | `QnapAPIError` | Unexpected or malformed API response |
145
+
146
+ ## HTTPS / Self-Signed Certificates
147
+
148
+ ```python
149
+ client = QnapClient("nas.local", 443, "admin", "password", ssl=True, verify_ssl=False)
150
+ ```
151
+
152
+ ## Home Assistant Integration
153
+
154
+ This library is the backing library for the [QNAP NAS Integration for Home Assistant](https://github.com/disforw/qnap).
155
+
156
+ ## Contributing
157
+
158
+ PRs welcome. This library is actively maintained. If your QNAP model returns unexpected data, open an issue with the raw API response and we'll fix it.
159
+
160
+ ## License
161
+
162
+ MIT
@@ -0,0 +1,134 @@
1
+ # QNAP NAS Integration for Home Assistant
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/qnap-client.svg)](https://pypi.org/project/qnap-client/)
4
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+
7
+ Async Python client for QNAP NAS. Replaces the unmaintained `python-qnapstats` with a fully async, `aiohttp`-based library with typed models, proper exception handling, Container Station support, and graceful handling of unexpected API responses.
8
+
9
+ ## Why This Exists
10
+
11
+ `python-qnapstats` hasn't had a meaningful update in years. Fan sensor support and external drive support were added to the source repo but never published to PyPI. The library is synchronous, has no typed return values, and crashes on certain NAS models due to missing key handling.
12
+
13
+ This library fixes all of that.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install qnap-client
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```python
24
+ import asyncio
25
+ from qnap_client import QnapClient
26
+
27
+ async def main():
28
+ async with QnapClient("192.168.1.100", 8080, "admin", "password") as client:
29
+ data = await client.get_all()
30
+ print(f"NAS: {data.system_info.name} ({data.system_info.model})")
31
+ print(f"CPU: {data.system_info.cpu_usage_percent:.1f}%")
32
+ print(f"Health: {data.system_health.status}")
33
+ for vol in data.volumes:
34
+ used_pct = vol.used_bytes / vol.total_bytes * 100
35
+ print(f"Volume {vol.name}: {used_pct:.1f}% used")
36
+ if data.firmware_update.latest_version:
37
+ print(f"Firmware update available: {data.firmware_update.latest_version}")
38
+
39
+ asyncio.run(main())
40
+ ```
41
+
42
+ ## API Reference
43
+
44
+ ### `QnapClient`
45
+
46
+ ```python
47
+ QnapClient(
48
+ host: str,
49
+ port: int,
50
+ username: str,
51
+ password: str,
52
+ *,
53
+ ssl: bool = False,
54
+ verify_ssl: bool = True,
55
+ timeout: int = 10,
56
+ session: aiohttp.ClientSession | None = None,
57
+ )
58
+ ```
59
+
60
+ | Method | Returns | Description |
61
+ |---|---|---|
62
+ | `login()` | `None` | Authenticate and store session ID |
63
+ | `logout()` | `None` | Log out and clear session |
64
+ | `get_system_info()` | `SystemInfo` | CPU, memory, firmware version, uptime |
65
+ | `get_system_health()` | `SystemHealth` | Overall health status string |
66
+ | `get_network_interfaces()` | `list[NetworkInterface]` | Per-interface RX/TX rates |
67
+ | `get_drive_health()` | `list[DriveHealth]` | S.M.A.R.T. status + temperature per drive |
68
+ | `get_volumes()` | `list[VolumeStats]` | Storage volume usage |
69
+ | `get_firmware_update()` | `FirmwareUpdate` | Current + latest firmware version |
70
+ | `get_fans()` | `list[FanStatus]` | Fan speed RPM (empty list if unsupported) |
71
+ | `get_external_drives()` | `list[ExternalDrive]` | External USB/eSATA drives |
72
+ | `get_all()` | `NasData` | All of the above in parallel |
73
+
74
+ ### `ContainerStationClient`
75
+
76
+ ```python
77
+ from qnap_client import ContainerStationClient
78
+
79
+ async with QnapClient(...) as client:
80
+ cs = ContainerStationClient(client)
81
+ containers = await cs.get_containers()
82
+ await cs.stop_container(containers[0].id)
83
+ ```
84
+
85
+ | Method | Returns | Description |
86
+ |---|---|---|
87
+ | `get_containers()` | `list[Container]` | All containers with id, name, status, image, type |
88
+ | `start_container(id, type)` | `None` | Start a container |
89
+ | `stop_container(id, type)` | `None` | Stop a container |
90
+ | `restart_container(id, type)` | `None` | Restart a container |
91
+ | `container_action(id, type, action)` | `None` | Generic action (start/stop/restart) |
92
+
93
+ ### Models
94
+
95
+ | Model | Fields |
96
+ |---|---|
97
+ | `SystemInfo` | `name`, `model`, `serial_number`, `firmware_version`, `uptime_seconds`, `cpu_usage_percent`, `memory_total_mb`, `memory_free_mb`, `memory_used_mb` |
98
+ | `SystemHealth` | `status` |
99
+ | `NetworkInterface` | `name`, `mac`, `ip`, `rx_bytes_per_sec`, `tx_bytes_per_sec` |
100
+ | `DriveHealth` | `drive_number`, `model`, `health`, `temperature` |
101
+ | `VolumeStats` | `name`, `total_bytes`, `used_bytes`, `free_bytes`, `status` |
102
+ | `FirmwareUpdate` | `current_version`, `latest_version` (None = up to date) |
103
+ | `FanStatus` | `fan_number`, `speed_rpm` |
104
+ | `ExternalDrive` | `name`, `total_bytes`, `used_bytes`, `free_bytes` |
105
+ | `Container` | `id`, `name`, `status`, `image`, `type` |
106
+ | `NasData` | All of the above combined |
107
+
108
+ ### Exceptions
109
+
110
+ | Exception | When |
111
+ |---|---|
112
+ | `QnapError` | Base exception |
113
+ | `QnapAuthError` | Bad credentials or session expired |
114
+ | `QnapConnectionError` | NAS unreachable |
115
+ | `QnapTimeoutError` | Request timed out |
116
+ | `QnapAPIError` | Unexpected or malformed API response |
117
+
118
+ ## HTTPS / Self-Signed Certificates
119
+
120
+ ```python
121
+ client = QnapClient("nas.local", 443, "admin", "password", ssl=True, verify_ssl=False)
122
+ ```
123
+
124
+ ## Home Assistant Integration
125
+
126
+ This library is the backing library for the [QNAP NAS Integration for Home Assistant](https://github.com/disforw/qnap).
127
+
128
+ ## Contributing
129
+
130
+ PRs welcome. This library is actively maintained. If your QNAP model returns unexpected data, open an issue with the raw API response and we'll fix it.
131
+
132
+ ## License
133
+
134
+ MIT
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "qnap-client"
7
+ version = "1.0.0"
8
+ description = "Async Python client for QNAP NAS — replaces python-qnapstats"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [{ name = "disforw", email = "disforw@users.noreply.github.com" }]
12
+ keywords = ["qnap", "nas", "homeassistant", "async", "aiohttp", "container-station"]
13
+ classifiers = [
14
+ "Development Status :: 5 - Production/Stable",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Topic :: Home Automation",
20
+ "Framework :: AsyncIO",
21
+ ]
22
+ requires-python = ">=3.12"
23
+ dependencies = [
24
+ "aiohttp>=3.9.0",
25
+ "xmltodict>=0.13.0",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ dev = [
30
+ "pytest>=8.0",
31
+ "pytest-asyncio>=0.23",
32
+ "aioresponses>=0.7",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/disforw/python-qnap"
37
+ Repository = "https://github.com/disforw/python-qnap"
38
+ Issues = "https://github.com/disforw/python-qnap/issues"
39
+ Changelog = "https://github.com/disforw/python-qnap/blob/main/CHANGELOG.md"
40
+
41
+ [tool.hatch.version]
42
+ path = "qnap_client/__init__.py"
43
+
44
+ [tool.pytest.ini_options]
45
+ asyncio_mode = "auto"
@@ -0,0 +1,55 @@
1
+ """qnap-client — Async Python client for QNAP NAS."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .client import QnapClient
6
+ from .container_station import ContainerStationClient
7
+ from .exceptions import (
8
+ QnapAPIError,
9
+ QnapAuthError,
10
+ QnapConnectionError,
11
+ QnapError,
12
+ QnapTimeoutError,
13
+ )
14
+ from .models import (
15
+ Container,
16
+ CpuStats,
17
+ DriveHealth,
18
+ ExternalDrive,
19
+ FanStatus,
20
+ FirmwareUpdate,
21
+ MemoryStats,
22
+ NasData,
23
+ NetworkInterface,
24
+ SystemHealth,
25
+ SystemInfo,
26
+ VolumeStats,
27
+ )
28
+
29
+ __version__ = "1.0.0"
30
+
31
+ __all__ = [
32
+ "QnapClient",
33
+ "ContainerStationClient",
34
+ # Exceptions
35
+ "QnapError",
36
+ "QnapAuthError",
37
+ "QnapConnectionError",
38
+ "QnapTimeoutError",
39
+ "QnapAPIError",
40
+ # Models
41
+ "SystemInfo",
42
+ "SystemHealth",
43
+ "CpuStats",
44
+ "MemoryStats",
45
+ "NetworkInterface",
46
+ "DriveHealth",
47
+ "VolumeStats",
48
+ "FirmwareUpdate",
49
+ "FanStatus",
50
+ "ExternalDrive",
51
+ "Container",
52
+ "NasData",
53
+ # Version
54
+ "__version__",
55
+ ]