Python client library for Unraid's official GraphQL API
Project description
unraid-api
An async Python client library for the Unraid GraphQL API (v4.21.0+, Unraid 7.1.4+).
Features
- 🔄 Async/await - Built with
aiohttpfor non-blocking operations - 🏠 Home Assistant ready - Accepts external
aiohttp.ClientSessionfor integration - 🔒 Secure by design - GraphQL variables, no string interpolation
- 📦 Typed - Full type hints with
py.typedmarker (PEP 561) - 🧩 Pydantic models - Structured response parsing
- 🔌 SSL auto-discovery - Handles Unraid's "No", "Yes", and "Strict" SSL modes
- ⚡ Redirect handling - Supports myunraid.net remote access
Installation
pip install unraid-api
Quick Start
import asyncio
from unraid_api import UnraidClient
async def main():
async with UnraidClient("192.168.1.100", "your-api-key") as client:
# Test connection
if await client.test_connection():
print("Connected!")
# Get version info
version = await client.get_version()
print(f"Unraid {version['unraid']}, API {version['api']}")
asyncio.run(main())
Usage Examples
Basic Queries
async with UnraidClient(host, api_key) as client:
# Custom GraphQL query
result = await client.query("""
query {
info {
os { hostname uptime }
cpu { name cores threads }
memory { total used }
}
}
""")
print(result["info"]["os"]["hostname"])
Docker Container Control
async with UnraidClient(host, api_key) as client:
# Start a container
await client.start_container("container:plex")
# Stop a container
await client.stop_container("container:plex")
VM Management
async with UnraidClient(host, api_key) as client:
# Start a VM
await client.start_vm("vm:windows-11")
# Stop a VM
await client.stop_vm("vm:windows-11")
Array Operations
async with UnraidClient(host, api_key) as client:
# Start/stop array
await client.start_array()
await client.stop_array()
# Parity check
await client.start_parity_check(correct=True)
await client.pause_parity_check()
await client.resume_parity_check()
await client.cancel_parity_check()
# Disk spin control
await client.spin_up_disk("disk:1")
await client.spin_down_disk("disk:1")
Session Injection (Home Assistant)
import aiohttp
from unraid_api import UnraidClient
async def setup_client(session: aiohttp.ClientSession):
"""Use shared session from Home Assistant."""
client = UnraidClient(
host="192.168.1.100",
api_key="your-api-key",
session=session, # Injected session won't be closed by client
verify_ssl=False,
)
return client
Pydantic Models
Response data can be parsed into typed models:
from unraid_api.models import DockerContainer, VmDomain, UnraidArray
# Parse container data
container = DockerContainer(**container_data)
print(f"{container.name}: {container.state}")
# Parse array data
array = UnraidArray(**array_data)
print(f"Array: {array.state}, Capacity: {array.capacity.usage_percent}%")
Exception Handling
from unraid_api import UnraidClient
from unraid_api.exceptions import (
UnraidAPIError,
UnraidAuthenticationError,
UnraidConnectionError,
UnraidSSLError,
UnraidTimeoutError,
)
async with UnraidClient(host, api_key) as client:
try:
await client.query("query { online }")
except UnraidAuthenticationError:
print("Invalid API key")
except UnraidSSLError:
print("SSL certificate verification failed")
except UnraidConnectionError:
print("Cannot reach server")
except UnraidTimeoutError:
print("Request timed out")
except UnraidAPIError as e:
print(f"API error: {e}")
API Reference
UnraidClient
Core Methods
| Method | Description |
|---|---|
test_connection() |
Test if server is reachable |
get_version() |
Get Unraid and API version |
get_server_info() |
Get server info for device registration |
query(query, variables) |
Execute GraphQL query |
mutate(mutation, variables) |
Execute GraphQL mutation |
High-Level Typed Methods (Pydantic Models)
| Method | Returns | Description |
|---|---|---|
get_system_metrics() |
SystemMetrics |
CPU, memory, temperature, power, uptime |
typed_get_array() |
UnraidArray |
Array state, capacity, disks |
typed_get_containers() |
list[DockerContainer] |
All Docker containers |
typed_get_vms() |
list[VmDomain] |
All virtual machines |
typed_get_ups_devices() |
list[UPSDevice] |
UPS devices with battery info |
typed_get_shares() |
list[Share] |
User shares with usage |
get_notification_overview() |
NotificationOverview |
Notification counts |
typed_get_vars() |
Vars |
System configuration variables |
typed_get_registration() |
Registration |
License information |
typed_get_services() |
list[Service] |
System services status |
typed_get_flash() |
Flash |
Flash drive info |
typed_get_owner() |
Owner |
Owner information |
typed_get_plugins() |
list[Plugin] |
Installed API plugins |
typed_get_docker_networks() |
list[DockerNetwork] |
Docker networks |
typed_get_log_files() |
list[LogFile] |
Available log files |
typed_get_cloud() |
Cloud |
Unraid Connect cloud status |
typed_get_connect() |
Connect |
Connect configuration |
typed_get_remote_access() |
RemoteAccess |
Remote access settings |
Raw Data Methods
| Method | Returns | Description |
|---|---|---|
get_array_status() |
dict |
Array state and capacity |
get_disks() |
list[dict] |
Physical disks |
get_shares() |
list[dict] |
User shares |
get_containers() |
list[dict] |
Docker containers |
get_vms() |
list[dict] |
Virtual machines |
get_ups_status() |
list[dict] |
UPS devices |
get_notifications() |
list[dict] |
Notifications |
get_parity_history() |
list[dict] |
Parity check history |
get_services() |
list[dict] |
System services |
get_plugins() |
list[dict] |
Installed plugins |
get_docker_networks() |
list[dict] |
Docker networks |
get_log_files() |
list[dict] |
Log files |
get_log_file(path) |
dict |
Log file contents |
Control Methods
| Method | Description |
|---|---|
start_container(id) |
Start Docker container |
stop_container(id) |
Stop Docker container |
restart_container(id) |
Restart Docker container |
start_vm(id) |
Start VM |
stop_vm(id) |
Stop VM (graceful) |
force_stop_vm(id) |
Force stop VM |
pause_vm(id) |
Pause VM |
resume_vm(id) |
Resume paused VM |
start_array() |
Start disk array |
stop_array() |
Stop disk array |
start_parity_check(correct) |
Start parity check |
pause_parity_check() |
Pause parity check |
resume_parity_check() |
Resume parity check |
cancel_parity_check() |
Cancel parity check |
spin_up_disk(id) |
Spin up disk |
spin_down_disk(id) |
Spin down disk |
Models
System Models
ServerInfo- Server info for HA device registrationSystemInfo- System informationSystemMetrics- CPU, memory, temperature, power, uptime metricsVars- System configuration variablesRegistration- License/registration infoFlash- Flash drive informationOwner- Server owner info
Storage Models
UnraidArray- Array state and disksArrayDisk- Individual array diskArrayCapacity- Capacity calculationsPhysicalDisk- Physical disk detailsShare- User share with usage
Docker/VM Models
DockerContainer- Container with ports, state, mountsDockerNetwork- Docker network configurationVmDomain- Virtual machine details
Service Models
Service- System service statusUPSDevice- UPS with battery/power infoPlugin- Installed plugin infoLogFile- Log file metadataLogFileContent- Log file contents
Network Models
Cloud- Unraid Connect cloud statusConnect- Connect configurationRemoteAccess- Remote access settings
Notification Models
Notification- System notificationNotificationOverview- Notification counts
Exceptions
| Exception | Parent | Description |
|---|---|---|
UnraidAPIError |
Exception |
Base exception for all API errors |
UnraidConnectionError |
UnraidAPIError |
Connection failures |
UnraidSSLError |
UnraidConnectionError |
SSL certificate verification failures |
UnraidAuthenticationError |
UnraidAPIError |
Authentication failures (invalid API key) |
UnraidTimeoutError |
UnraidAPIError |
Request timeout |
Note: UnraidSSLError inherits from UnraidConnectionError, so it can be caught with either exception type for backwards compatibility.
Requirements
- Python 3.11+
- Unraid 7.1.4+ with API 4.21.0+
- API key with appropriate permissions
Development
# Clone repository
git clone https://github.com/ruaan-deysel/unraid-api.git
cd unraid-api
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v --cov=src/unraid_api
# Lint and type check
ruff check .
ruff format .
mypy src/
License
MIT License - see LICENSE for details.
Contributing
Contributions welcome! Please ensure:
- Tests are written first (TDD)
- All tests pass with 80%+ coverage
- No linting errors (
ruff check . && mypy src/) - GraphQL variables used (no string interpolation)
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unraid_api-1.5.0.tar.gz.
File metadata
- Download URL: unraid_api-1.5.0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0b260236ea62cba478812e4c6e764322779b0b1388ddaf1daed6c7dc62dad71
|
|
| MD5 |
157095895155b86a24b805806ee940ac
|
|
| BLAKE2b-256 |
763d1406ea429e882a52225b75bbc5d1fe67b2955ab445f433891e4410dba679
|
Provenance
The following attestation bundles were made for unraid_api-1.5.0.tar.gz:
Publisher:
publish.yml on ruaan-deysel/unraid-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unraid_api-1.5.0.tar.gz -
Subject digest:
c0b260236ea62cba478812e4c6e764322779b0b1388ddaf1daed6c7dc62dad71 - Sigstore transparency entry: 926845663
- Sigstore integration time:
-
Permalink:
ruaan-deysel/unraid-api@b04b90bc5b62cd47951ecf533efa36666051110d -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/ruaan-deysel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b04b90bc5b62cd47951ecf533efa36666051110d -
Trigger Event:
release
-
Statement type:
File details
Details for the file unraid_api-1.5.0-py3-none-any.whl.
File metadata
- Download URL: unraid_api-1.5.0-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb496fd1f4e741b8bd1cb97e3130abcadc3fcef65e58f543dc1d40ad433d516
|
|
| MD5 |
55efeed57489b48aab10afa9888e48fc
|
|
| BLAKE2b-256 |
d9e7ff5302b7193faff1f399b021448ef435841017e0593d2a7659e781013ceb
|
Provenance
The following attestation bundles were made for unraid_api-1.5.0-py3-none-any.whl:
Publisher:
publish.yml on ruaan-deysel/unraid-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unraid_api-1.5.0-py3-none-any.whl -
Subject digest:
eeb496fd1f4e741b8bd1cb97e3130abcadc3fcef65e58f543dc1d40ad433d516 - Sigstore transparency entry: 926845664
- Sigstore integration time:
-
Permalink:
ruaan-deysel/unraid-api@b04b90bc5b62cd47951ecf533efa36666051110d -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/ruaan-deysel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b04b90bc5b62cd47951ecf533efa36666051110d -
Trigger Event:
release
-
Statement type: