thirdtrail
Python client for the thirdtrail APIs: sun, moon,
twilight, solar irradiance and tides for any point on Earth. Sun and moon
times are corrected for the elevation you pass in.
Why elevation
Most sunrise APIs answer for an observer standing at sea level. The higher you
are, the further you can see, and the earlier the sun clears the horizon.
At the Cliffs of Moher (214 m) the difference is about three minutes, and
it moves sunrise, sunset and every golden- and blue-hour boundary with them:
Golden hour lasts 20 to 40 minutes, so three minutes is a noticeable share of
it. Pass elevation whenever you know it.
What you get
Timestamps arrive as aware datetime objects, not strings. Anything the
client does not model is still available on day.raw and day.response, so
you can use a new server-side field before the client catches up.
Endpoints
Tides take no elevation, with one exception
tide_heights and tide_extremes have no elevation parameter on purpose,
because how high you stand doesn't change the ocean surface. If you pass
one, you get a TypeError instead of having it silently ignored.
tide_window is the exception, because half of what it returns is sun and
moon data:
Tide heights are metres relative to mean sea level, not chart datum, and
they exclude weather-driven surge. Not for navigation.
Errors
Each kind of failure has its own exception class, so you can catch the one you
care about instead of parsing error messages:
AuthenticationError (401), PermissionDenied (403, a tier you are not on),
PlanLimitExceeded and InvalidRequest (400), RateLimited (429),
DataUnavailable (503), ServerError (5xx). All subclass ThirdtrailError.
Transient failures and 429s are retried with backoff. Plan limits are not
retried, because the same request would fail the same way every time.
Keys
Create one at thirdtrail.life/apis/keys/.
A key belongs to one subscription, so it works with one API; a Tides key
calling a solar endpoint gets PermissionDenied.
Every API has a free tier.
Not covered yet
The client doesn't cover the bulk (POST) endpoints, iCalendar feeds or
webhook management yet. For those, call the REST API directly; the full
contract is published as OpenAPI 3.1.
Using an AI agent? There is an MCP server
that exposes the same data as tools.
Licence
MIT