Python library for controlling and monitoring Unraid servers via GraphQL API
Project description
unraid-api: Python Library for Unraid GraphQL API
A comprehensive Python library that provides a clean, intuitive interface to Unraid's GraphQL API. It enables developers to programmatically control and monitor Unraid servers with both synchronous and asynchronous support, strong typing, and intelligent error handling.
Features
- Complete coverage of Unraid GraphQL API endpoints
- Both synchronous and asynchronous client interfaces
- Strongly-typed Pydantic models
- Comprehensive error handling
- API key authentication
- Built-in query caching
- Real-time subscription support
- Extensive documentation and examples
- Command-line interface tool
Installation
pip install unraid-api
Note: While the package is installed with pip install unraid-api, you import it in your code using import unraid_api or from unraid_api import UnraidClient.
Enabling the Unraid GraphQL API
Before you can use this library, you need to enable the GraphQL API on your Unraid server and generate an API key.
Enabling the GraphQL Sandbox
-
Enable developer mode using the CLI on your Unraid server:
unraid-api developer -
Follow the prompts to enable the sandbox. This will allow you to access the Apollo Sandbox interface.
-
Access the GraphQL playground by navigating to:
http://YOUR_SERVER_IP/graphql
Creating an API Key
-
Use the CLI on your Unraid server to create an API key:
unraid-api apikey --create
-
Follow the prompts to set:
- Name
- Description
- Roles
- Permissions
-
The generated API key should be used with this library as shown in the examples below.
Quick Start
Synchronous Usage
from unraid_api import UnraidClient
# Connect to Unraid server with API key
client = UnraidClient("192.168.1.10", api_key="your-api-key")
# Note: Unraid servers often redirect to myunraid.net domains
# The client automatically handles these redirects
# Get system info
system_info = client.get_system_info()
print(f"System version: {system_info.version}")
# Start the array
client.array.start_array()
# Get Docker containers
containers = client.docker.get_containers()
for container in containers:
print(f"Container: {container.name}, Status: {container.status}")
Asynchronous Usage
import asyncio
from unraid_api import AsyncUnraidClient
async def main():
client = AsyncUnraidClient("192.168.1.10", api_key="your-api-key")
# Get all Docker containers
containers = await client.docker.get_containers()
for container in containers:
print(f"Container: {container.name}, Status: {container.status}")
# Perform a parity check
await client.array.start_parity_check()
asyncio.run(main())
Command-line Interface
The package also includes a command-line interface for quick interactions with Unraid servers:
# Display system information
unraid-cli --ip 192.168.1.10 --api-key YOUR_API_KEY system
# List Docker containers
unraid-cli --ip 192.168.1.10 --api-key YOUR_API_KEY docker
# Show array status
unraid-cli --ip 192.168.1.10 --api-key YOUR_API_KEY array
API Documentation
Core Resources
- Array: Control and monitor the Unraid array
start_array(),stop_array(),get_array_status()
- Disk: Manage disks and storage
get_disks(),mount_disk(),unmount_disk()
- Docker: Control Docker containers
get_containers(),start_container(),stop_container(),restart_container()
- VM: Manage virtual machines
get_vms(),start_vm(),stop_vm(),restart_vm()
- System: System operations and information
reboot(),shutdown(),get_system_info()
- User: Manage users and permissions
get_users(),add_user(),delete_user()
- Notification: Handle Unraid notifications
get_notifications(),create_notification(),archive_notification()
Advanced Usage
Real-time Subscriptions
import asyncio
from unraid_api import AsyncUnraidClient
async def main():
client = AsyncUnraidClient("192.168.1.10", api_key="your-api-key")
# Subscribe to Docker container updates
async for update in client.docker.subscribe_to_containers():
print(f"Container update: {update.name} is now {update.status}")
asyncio.run(main())
Error Handling
from unraid_api import UnraidClient
from unraid_api.exceptions import AuthenticationError, ConnectionError, APIError
try:
client = UnraidClient("192.168.1.10", api_key="invalid-api-key")
system_info = client.info.get_system_info()
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ConnectionError as e:
print(f"Connection error: {e}")
except APIError as e:
print(f"API error: {e}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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.0.0.tar.gz.
File metadata
- Download URL: unraid_api-1.0.0.tar.gz
- Upload date:
- Size: 40.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11afedfbfd055c4727b0923e1b46b149db62882b79071d2ba453bc1b0b1cd29
|
|
| MD5 |
8fea9a5a2036422b1316f1a25b46bbbd
|
|
| BLAKE2b-256 |
81d4eacb2beac1fb630a40f1d7695bfee3a0d27c341183bec7fc066137c169de
|
Provenance
The following attestation bundles were made for unraid_api-1.0.0.tar.gz:
Publisher:
publish.yml on domalab/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.0.0.tar.gz -
Subject digest:
b11afedfbfd055c4727b0923e1b46b149db62882b79071d2ba453bc1b0b1cd29 - Sigstore transparency entry: 192943006
- Sigstore integration time:
-
Permalink:
domalab/unraid-api@02539391e63c54e4849d3846be784c066e933593 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/domalab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02539391e63c54e4849d3846be784c066e933593 -
Trigger Event:
release
-
Statement type:
File details
Details for the file unraid_api-1.0.0-py3-none-any.whl.
File metadata
- Download URL: unraid_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 50.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00c264bc63a273155f486d644d37dccbe254fe10ce0b84f967a78dfb9366bbc7
|
|
| MD5 |
56e4d85f43f084c4a861d9ed1597bd07
|
|
| BLAKE2b-256 |
c4cb29212acde486dcf7182642e2fd2bd522e9c3e8349d9464931569ae3c3fe4
|
Provenance
The following attestation bundles were made for unraid_api-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on domalab/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.0.0-py3-none-any.whl -
Subject digest:
00c264bc63a273155f486d644d37dccbe254fe10ce0b84f967a78dfb9366bbc7 - Sigstore transparency entry: 192943008
- Sigstore integration time:
-
Permalink:
domalab/unraid-api@02539391e63c54e4849d3846be784c066e933593 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/domalab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@02539391e63c54e4849d3846be784c066e933593 -
Trigger Event:
release
-
Statement type: