Python SDK for the Tempest API.
Requires Python 3.11+.
- From PyPI:
pip install tempestwxEnsure TEMPEST_ACCESS_TOKEN is set (via environment or .env).
from tempestwx import Tempest
# Recommended: Use context manager for automatic resource cleanup
with Tempest() as twx:
stations = twx.stations()
print(stations)
# Alternative: Manual resource management
twx = Tempest()
try:
stations = twx.stations()
print(stations)
finally:
twx.close()The client returns Pydantic models. Use .model_dump() to convert to dict when needed.
The client uses a deterministic cascade to resolve configuration:
- Library defaults (built‑in constants)
config.json(first existing among:$TEMPEST_CONFIG_PATH,./config.json).envfile (loaded automatically once, without overriding already exported environment vars)- Live environment variables (take precedence over
.envvalues) - Explicit parameters passed to
Tempest(...)(highest precedence)
Resolved values are materialized into an immutable Settings instance:
from tempestwx.settings_loader import load_settings
settings = load_settings()
print(settings.api_uri, settings.token)You can explicitly override when constructing the client:
from tempestwx import Tempest
with Tempest(token="OVERRIDE_TOKEN") as twx:
stations = twx.stations()Or derive a modified settings object:
from tempestwx.settings_loader import load_settings
base = load_settings()
custom = base.with_overrides(api_uri="https://example.test/api/")
with Tempest(settings=custom) as twx:
stations = twx.stations()Supported variables:
TEMPEST_ACCESS_TOKEN– API auth tokenTEMPEST_API_URI– Base API URI (defaults tohttps://swd.weatherflow.com/swd/rest/)TEMPEST_CONFIG_PATH– Optional path to a JSON config file (fallbacks to./config.json)- Unit overrides (optional):
TEMPEST_DEFAULT_UNIT_TEMPERATURETEMPEST_DEFAULT_UNIT_PRESSURETEMPEST_DEFAULT_UNIT_WINDTEMPEST_DEFAULT_UNIT_DISTANCETEMPEST_DEFAULT_UNIT_PRECIPTEMPEST_DEFAULT_UNIT_BRIGHTNESSTEMPEST_DEFAULT_UNIT_SOLAR_RADIATIONTEMPEST_DEFAULT_UNIT_BUCKET_STEP_MINUTES
If a .env file exists in the working directory, it is loaded automatically (without overriding already exported variables) the first time load_settings() runs.
Example .env:
TEMPEST_ACCESS_TOKEN=your-token-hereIf present, values provide defaults that can be overridden by environment variables:
{
"api_uri": "https://swd.weatherflow.com/swd/rest/",
"default_unit_temperature": "c",
"default_unit_pressure": "mb",
"default_unit_wind": "mps",
"default_unit_distance": "km",
"default_units_precip": "mm",
"default_units_brightness": "lux",
"default_units_solar_radiation": "w/m2",
"default_units_bucket_step_minutes": 1
}Note: tokens are not read from config.json. Use environment variables or .env for TEMPEST_ACCESS_TOKEN.
Caching avoids repeated disk & env parsing. To pick up changes at runtime:
from tempestwx.settings_loader import reload_settings
reload_settings() # clears cache and re-evaluates cascadeYou can supply partial unit overrides via UnitsOverrides (only fields you specify are changed):
from tempestwx import Tempest
from tempestwx.settings import UnitsOverrides
from tempestwx.settings_loader import load_settings
base = load_settings()
custom = base.with_overrides(units_overrides=UnitsOverrides(temp="f", wind="mph"))
with Tempest(settings=custom) as twx:
forecast = twx.better_forecast(station_id=12345)Temporarily swap tokens within a context:
from tempestwx import Tempest
with Tempest() as twx:
# Use default token
stations = twx.stations()
# Temporarily use different token
with twx.token_as("temporary-token"):
other_stations = twx.stations()
# Back to default token
more_stations = twx.stations()All endpoints support async when the client is created with asynchronous=True:
import asyncio
from tempestwx import Tempest
async def main():
# Use async context manager for proper cleanup
async with Tempest(asynchronous=True) as twx:
stations = await twx.stations()
print(stations)
asyncio.run(main())- OAuth Authorization Code (with PKCE) grant types
- Additional Tempest APIs, e.g. TempestOne
- Standalone documentation with MkDocs