Authentication¶
Every request needs an API key. Create one in the wxchange app at https://app.wxchange.io, under Settings → API keys.
from stormlore import Client
client = Client(api_key="sg_live_...")
or, keeping the key out of your code:
export WXCHANGE_API_KEY=sg_live_...
client = Client()
The argument wins over the environment variable. Leading and trailing whitespace (a
pasted newline) is stripped. With no key at all, the client raises MissingApiKeyError
when it is created, before any request is sent.
A key the API refuses (mistyped, expired or revoked) raises UnauthorizedError on the
first request, with the same pointer to where keys are made.
Which API¶
The client talks to https://api.wxchange.io. To use another deployment (staging, or a
local API), pass base_url or set WXCHANGE_API_URL:
client = Client(base_url="https://api.dev.wxchange.io")
Scopes¶
A key carries scopes. Forecast queries need read:forecasts, the model listings
read:models. Giving a place as a ZIP code needs read:observations too (the ZIP is
looked up with the ZIP endpoint); without it the client raises ZipLookupForbiddenError.
Pass the place as (lat, lon) instead, or add the scope to the key.
What the client sends¶
Authorization: Bearer <key> and User-Agent: stormlore/<version> python/<x.y> on every
request. The key is never printed: repr(client) shows only the base URL.