Thalovant Python SDK
Python SDK for connecting apps, services, kiosks, and agents to Thalovant hubs.
The control API is used to discover hubs and provision a client identity. After that, the SDK talks directly to the hub data plane over HTTPS, WSS, or MQTTS.
Thalovant API -> discover hubs, create client identity
Python SDK -> connect to the hub data plane
Hub runtime -> skills, events, replies
The SDK is asyncio at its core. AsyncThalovantClient and
AsyncThalovantControlPlane are the implementation; ThalovantClient and
ThalovantControlPlane run the same code on a private event-loop thread, so a
script, a CLI or a voice satellite can call them without an event loop of its
own.
Requirements
- Python 3.10 or newer.
- A Thalovant account with API access for authenticated control-plane actions.
- A hub id or slug, and a client identity for that hub. You can create one through the API or use one downloaded from the dashboard.
Install
pip install thalovant
Optional extras: thalovant[mqtt], thalovant[yaml] and thalovant[listing].
The documentation says what each one adds.
Quick start
from thalovant import ThalovantClient, ThalovantControlPlane
api = ThalovantControlPlane()
# Public hub discovery does not require auth.
public_hubs = api.list_public_hubs(limit=12)
for hub in public_hubs["data"]:
print(hub["id"], hub["slug"], hub["title"])
# Auth is required when creating a client identity. This opens the browser on
# this machine, or prints a code to approve from any browser where there is none.
api.interactive_login()
result = api.create_client_identity(
"hub-id",
name="python-demo-client",
preferred_protocols=("wss", "https", "mqtt"),
)
with ThalovantClient(result.identity, protocol="wss") as client:
info = client.connection_info()
print("connected in", info.connect_ms, "ms")
reply = client.ask("Tell me a short clean joke.")
print(reply.text)
Keep result secret: result.identity and the raw result.client API resource
carry the client credentials. result.as_dict() redacts every secret and is
safe to log; result.as_dict(include_secrets=True) returns the real
credentials, so use it only to save the identity and never log it.
Sign in
from thalovant import ThalovantControlPlane
api = ThalovantControlPlane()
api.interactive_login() # the browser here, or a device code where there is none
# method="browser" or method="device" forces one.
interactive_login() opens your browser at the Thalovant consent page and
listens on 127.0.0.1 for the answer (OAuth with PKCE on a loopback redirect,
RFC 8252). It always prints the address too, in case the browser does not
open. The browser that approves hands the answer to its own computer, so a
sign-in link sent to somebody on another computer delivers nothing to you or to
them. (A forwarded port, such as ssh -L, or another user of the same computer
can still complete it.)
On a machine that cannot show a browser, it prints a code to enter at
thalovant.com/activate from any browser instead: over SSH, in CI, or on Linux
with neither DISPLAY nor WAYLAND_DISPLAY. It does the same against an API
that does not offer browser sign-in yet. browser_login() and
login_with_browser() (the device login) are the two methods on their own.
AsyncThalovantControlPlane has the same methods, awaited.
scopes= asks for what the token may do. The default is hubs:read and
clients:write. device_name= is what the consent page and the token show.
The default is thalovant-python-sdk on <hostname>.
The result is a scoped API token that lasts 365 days and is listed in the
dashboard. It counts against your plan. api.revoke_api_token() revokes it.
A denied sign-in raises ThalovantDeviceLoginDenied. A browser sign-in that
nobody answers within 300 seconds (timeout=) raises
ThalovantDeviceLoginExpired. Accounts with a password can still use
api.login(email, password).
Chat apps
A hub can answer in Telegram, Discord, Matrix, Mattermost or Twitch. Read the
owner's allowance first (Free plans allow none), connect the bot, then choose
where it answers. Credentials go in a SecretValue, which never prints.
import os
from thalovant import SecretValue, ThalovantControlPlane
api = ThalovantControlPlane(access_token=os.environ["THALOVANT_API_TOKEN"])
hub_id = os.environ["THALOVANT_HUB_ID"]
if not api.get_bridge_networks(hub_id).allowance.can_create:
raise SystemExit("The plan has no room for another chat app.")
# Telegram: a bot token.
telegram = api.create_bridge(hub_id, "telegram", token=SecretValue(os.environ["TELEGRAM_BOT_TOKEN"]))
chats = [chat for chat in api.list_bridge_chats(telegram.id) if chat.selectable]
if not chats:
raise SystemExit("Add the bot to a group and mention it there, then list the chats again.")
telegram = api.update_bridge(telegram.id, allowed=chats[:1], etag=telegram.etag)
api.send_bridge_test_message(telegram.id, telegram.allowed[0].id)
# Matrix: a homeserver and user, and an access token. Room ids are typed.
matrix = api.create_bridge(
hub_id, "matrix",
secrets={"access_token": SecretValue(os.environ["MATRIX_ACCESS_TOKEN"])},
settings={"homeserver": "https://matrix.example.org", "user_id": "@kitchen-hub:example.org"},
)
api.update_bridge(matrix.id, allowed=["!abcdefgh:example.org"])
# Twitch: bot login and client id, refresh token and client secret.
twitch = api.create_bridge(
hub_id, "twitch",
secrets={
"refresh_token": SecretValue(os.environ["TWITCH_REFRESH_TOKEN"]),
"client_secret": SecretValue(os.environ["TWITCH_CLIENT_SECRET"]),
},
settings={"bot_login": "kitchenhubbot", "client_id": os.environ["TWITCH_CLIENT_ID"]},
)
api.update_bridge(twitch.id, allowed=["#MyChannel"])
api.update_bridge(twitch.id, paused=True) # pause; paused=False resumes
print(api.get_bridge(telegram.id).status.reason) # Setup, Starting, Connected, Paused, ...
A refusal is a ThalovantAPIError with code and fields (the settings or
secrets it names); see the chat apps guide for the
status words, holds and every code.
Documentation
| Topic | Link |
|---|---|
| Python SDK: install, sign-in, identities, protocols, conversations, events, asyncio, Home Assistant, provisioning, errors, upgrading to 0.9 | https://docs.thalovant.com/developers/sdks/python/ |
| The Thalovant product | https://docs.thalovant.com |
Not yet in the online documentation
These parts of the old README have no counterpart on the documentation page.
They are described in the docs/ folder of this repository and in
CHANGELOG.md.
- Listing your hubs, workspace analytics and durable memory.
- Rich responses (
reply.display_items) and skill sounds (reply.media_events). - Actions and exact inputs (
send_action,send_code). - Reading an API error and the API shape overview.
- CLI diagnostics:
thalovant --identity _identity.json doctorchecks identity shape, endpoint selection, authentication, handshake and transport health.
Development
pip install -e ".[dev]"
pytest
Security
See SECURITY.md.
Licence
MIT. See LICENSE.
Metadata
Release files for thalovant 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| thalovant-0.11.0.tar.gz | 611.9 kB | Without provenance | Details for thalovant-0.11.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thalovant-0.11.0-py3-none-any.whl | Python 3 | none | any | Details for thalovant-0.11.0-py3-none-any.whl |
Total release size: 887.2 kB
Release files / thalovant-0.11.0.tar.gz
| Download URL | thalovant-0.11.0.tar.gz |
|---|---|
| Size | 611.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20b203bb1dc85cb706f01c66b8dadd1216489c4a7e18c7fb60089948d12324ad
|
|
BLAKE2b-256 checksum How to use checksums |
de14ef6c156c5549b8176c848f4adb0cf1c2756f48a2adff1c73d8b8236034f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / thalovant-0.11.0-py3-none-any.whl
| Download URL | thalovant-0.11.0-py3-none-any.whl |
|---|---|
| Size | 275.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63ec0ef41c68bb7489216a48826c0530991c6ad25d367ad1778818e83e5e71cd
|
|
BLAKE2b-256 checksum How to use checksums |
bc897dd51205aaeec267d5f17782ca1a5ae778a1fd1fbbd50e7735d6c3173206
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for thalovant 0.11.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.