aiotruenas
Asyncio-native Python client for the TrueNAS JSON-RPC 2.0 WebSocket API
(ws(s)://<host>/api/current, TrueNAS 25.04+).
No dependency on Home Assistant or any other framework — usable as a standalone library.
Installation
pip install .
Usage
import asyncio
from aiotruenas import TrueNASClient
async def main() -> None:
async with TrueNASClient("truenas.local", "1-abcdef...") as client:
info = await client.call("system.info")
print(info)
sub_id, _ = await client.subscribe("app.stats")
try:
events = await client.get_subscription_events(sub_id, event_timeout=5.0)
print(events)
finally:
await client.unsubscribe(sub_id)
asyncio.run(main())
call() is a generic RPC surface — pass any TrueNAS JSON-RPC method name and its params
(list or dict). Long-running operations that return a job id (scrub, replication, dataset
lock/unlock, ...) can be polled automatically with job=True:
await client.call("pool.scrub.scrub", ["tank", "START"], job=True)
Connection and protocol failures are raised as typed exceptions (see aiotruenas.exceptions)
rather than returned as an error code/string, so callers can except TrueNASAuthenticationError,
except TrueNASConnectionError, etc.
Normalized domain state
TrueNASState wraps a TrueNASClient and exposes one async def get_<endpoint>() method per
supported TrueNAS RPC endpoint. Each method queries the endpoint, normalizes the raw payload into
a stable dict-keyed-by-id shape, and caches the result on state.ds[<endpoint>]:
from aiotruenas import TrueNASClient, TrueNASState
async with TrueNASClient("truenas.local", "1-abcdef...") as client:
state = TrueNASState(client)
pools = await state.get_pool()
print(pools)
print(state.ds["pool"]) # same data, cached
Supported endpoints so far: get_pool(), get_dataset(), get_cloudsync(), get_replication(),
get_rsync(), get_snapshottask(), get_cronjob(), get_arc(), get_ups(), get_service(),
get_vm(), get_container(), get_app(), get_certificates(), get_directoryservices(),
get_alerts(), get_interface(), get_disk(), get_scrub(), get_smb(), get_update(),
get_systeminfo(), get_systemstats(). This covers the full endpoint set migrated from consumer
integrations' own normalization code — see MIGRATION_PLAN.md for details and
history.
get_arc()/get_ups()/get_alerts()/get_smb()/get_update()/get_systeminfo() are the
exception to the dict-keyed-by-id shape above: they have no natural object id and instead return a
flat dict of scalar/aggregate readings (e.g. {"battery_charge": 80.0, ...},
{"count": 2, "critical": 1, ...} for alerts, or {"connections": 3} for get_smb()).
get_systemstats() enriches that same flat ds["system_info"] dict (CPU/load/memory/ARC-size)
and, as a side effect, ds["interface"][id]["rx"/"tx"] (interface throughput) rather than
returning its own endpoint. Its underlying netdata graph queries are best-effort: a failed graph
leaves its field(s) at the previous value instead of failing the whole call. Check
state.systemstats_stale_graphs after calling it to see which graphs (if any) failed on the most
recent refresh, so a caller can distinguish a partially stale result from a fully fresh one.
get_ups()'s per-graph netdata queries follow the same best-effort/partial-staleness contract —
check state.ups_stale_graphs after calling it. One difference: a UPS graph that has never once
produced a reading has no field in the result at all, so a failure on it is not reflected in
ups_stale_graphs either — there's no previous value to call stale. An empty
ups_stale_graphs therefore means "no field is outdated", not "nothing failed", unlike
systemstats_stale_graphs, whose fields are always present from the start.
Status
Early development. Generic call() RPC surface plus a growing set of normalized TrueNASState
endpoints (no typed per-domain convenience methods elsewhere yet). See PROMPT.md for
the full design brief and CLAUDE.md for repo guidance.
License
Apache-2.0, see LICENSE.
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 aiotruenas-1.5.1.tar.gz.
File metadata
- Download URL: aiotruenas-1.5.1.tar.gz
- Upload date:
- Size: 98.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11a97673fe9d541cbb04ff071d6fa1bd4d007d66968d4f2fd539b4d2f0a9ae4a
|
|
| MD5 |
5659858d1b0e53c020662a35538c05ce
|
|
| BLAKE2b-256 |
90177abeaf3b7841369f4cbedfaa974551021c5d201642d4086076efda7449ba
|
Provenance
The following attestation bundles were made for aiotruenas-1.5.1.tar.gz:
Publisher:
pypi.yaml on kayl-codes/aiotruenas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotruenas-1.5.1.tar.gz -
Subject digest:
11a97673fe9d541cbb04ff071d6fa1bd4d007d66968d4f2fd539b4d2f0a9ae4a - Sigstore transparency entry: 2762656801
- Sigstore integration time:
-
Permalink:
kayl-codes/aiotruenas@468517663e57a165f198c2fece710744b4c02a66 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/kayl-codes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@468517663e57a165f198c2fece710744b4c02a66 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiotruenas-1.5.1-py3-none-any.whl.
File metadata
- Download URL: aiotruenas-1.5.1-py3-none-any.whl
- Upload date:
- Size: 59.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93346aa278dc83d0a6567eb0c4228f2cb2fa0d828acf4bfc026bab13272abe1c
|
|
| MD5 |
2c57406915e09d7970fc4dbdf5482a6c
|
|
| BLAKE2b-256 |
d0b322e7ce74073758513cb7a18ac9d275ace522328f2835bf39b7ed7ff202f2
|
Provenance
The following attestation bundles were made for aiotruenas-1.5.1-py3-none-any.whl:
Publisher:
pypi.yaml on kayl-codes/aiotruenas
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiotruenas-1.5.1-py3-none-any.whl -
Subject digest:
93346aa278dc83d0a6567eb0c4228f2cb2fa0d828acf4bfc026bab13272abe1c - Sigstore transparency entry: 2762656979
- Sigstore integration time:
-
Permalink:
kayl-codes/aiotruenas@468517663e57a165f198c2fece710744b4c02a66 -
Branch / Tag:
refs/tags/v1.5.1 - Owner: https://github.com/kayl-codes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@468517663e57a165f198c2fece710744b4c02a66 -
Trigger Event:
release
-
Statement type: