Python SDKDeveloper tools
A forecast in your terminal.
The question at our Montréal front door is rarely “What can this platform do?” It’s “Do I need the raincoat?” I wanted an answer I could slip into a morning report, read aloud on a Mark II or put on a little screen by the coats. Here’s my favourite place to start building that screen. Open a terminal. The drill can wait.
Resume at bookmarkFollow the forecast
with ThalovantControlPlane() as catalog:
hub = catalog.get_public_hub("daily-desk")
print(f"{hub['title']} ({hub['slug']})")if options.identity is None:
raise SystemExit(0)
identity = options.identity.expanduser()
if not identity.is_file():
raise SystemExit(f"The identity file could not be found: {identity}")
with ThalovantClient.from_identity_file(identity) as client: reply = client.ask(
f"What is the weather in {options.city}?",
lang="en-ca",
timeout=20,
)
if not reply.text:
raise SystemExit("The hub returned no weather text.")
print(reply.text)View the complete script
import argparse
from pathlib import Path
from thalovant import ThalovantClient, ThalovantControlPlane
parser = argparse.ArgumentParser()
parser.add_argument("--identity", type=Path)
parser.add_argument("--city", default="Montréal, Canada")
options = parser.parse_args()
with ThalovantControlPlane() as catalog:
hub = catalog.get_public_hub("daily-desk")
print(f"{hub['title']} ({hub['slug']})")
if options.identity is None:
raise SystemExit(0)
identity = options.identity.expanduser()
if not identity.is_file():
raise SystemExit(f"The identity file could not be found: {identity}")
with ThalovantClient.from_identity_file(identity) as client:
reply = client.ask(
f"What is the weather in {options.city}?",
lang="en-ca",
timeout=20,
)
if not reply.text:
raise SystemExit("The hub returned no weather text.")
print(reply.text)With no arguments, the program prints the name and slug from the public catalog. You can run this part without an account.
Supply --identity and the SDK opens the hub connection encoded in that file. The weather request goes to that hub.
The text in reply.text comes from the hub. Change --city to send a new question using the same connection.
Run it on your computer
Use Python 3.10 or newer in a virtual environment. Download the script into your working folder and run the guest lookup first.
python -m pip install thalovant
python forecast.pyGuest output
Daily Desk (daily-desk)For the forecast, create an API client in Daily Desk and download its identity JSON. Substitute the private file’s path below.
python forecast.py --identity "daily-desk.json" --city "Québec City, Canada"This run prints the hub’s current reply. Weather conditions and wording vary.
What the terminal has to prove
I can spend a perfectly good Saturday choosing the shape of a weather icon. Before the first pixel, though, I want to know whether a program can ask Daily Desk a plain question and get useful text back. If that works, an app with no microphone can use the same weather skill as the speaker in the kitchen. There’s no separate forecast to keep in sync.
Look up the address before knocking
Install the Python package and run the example with no options. It asks the public catalog for daily-desk and prints Daily Desk (daily-desk). That little line buys us something. We know Python can reach Thalovant’s catalog, the slug resolves to the hub we want, and we’ve done it without an account. No weather request has been sent yet.
You could list the first three public hubs instead. They change as new projects appear. Looking up one listing by slug keeps our first test about the coat by the door.
Give this script its own connection
Open Daily Desk in Explore, sign in, and create an API client for that hub. Download its identity JSON and keep it in a private folder. Think of it as the key to this particular connection. Your script needs the file path. The forecast on the screen has no business seeing the key.
Run the same script again with --identity pointing to the file. This time the SDK opens a connection to the hub. When the with block ends, Python closes that connection for you. You can run the one-shot script from a scheduler without leaving a client listening between requests.
Send the place and the language
The script asks “What is the weather in Montréal, Canada?” and requests Canadian English. There’s nothing to transcribe. The question is already text, and Daily Desk’s weather skill performs the lookup directly. The French example asks in French and sends fr-ca. A visitor writing a bilingual app can make that choice per request.
Now try another city with --city. Include the province or country if the name is ambiguous. I like that test because changing Montréal to Québec City should change the place in the answer without changing a single line of display code.
Put the reply somewhere useful
Start with print(reply.text). If the service returns a weather sentence, that’s the exact string your morning report can reuse. Temperatures and wording change, so test for a usable answer and the intended location. If you need a numeric temperature for a chart, use a documented structured weather source for that job. Taking the first number out of a sentence is how a perfectly innocent “feels like” ends up running the thermostat.
Figure out which door stayed closed
If discovery fails, check your internet connection and whether the Daily Desk listing opens in Explore. If the listing prints and the next step fails, you’ve already ruled out discovery. A missing file points to the path. A refused session points you back to the client identity and its hub. A timeout means the call didn’t get a reply before its deadline. Keep these cases separate in your app so a weather outage doesn’t look like a sunny day.