traefik
Async Python client for the Traefik API.
Read-only: version, the dashboard overview, entrypoints, HTTP routers and services, and — optionally — the handful of useful numbers from the Prometheus metrics endpoint.
Written for HA-Traefik, but it has no Home Assistant dependency and works anywhere.
Install
pip install traefik
Use
import asyncio
from traefik import TraefikClient
async def main() -> None:
async with TraefikClient("http://192.0.2.10:8080") as client:
info = await client.get_version()
print(info.version, info.codename)
overview = await client.get_overview()
print(overview.http_routers.total, "routers")
print(overview.http_routers.errors, "with errors")
for router in await client.list_routers():
print(router.name, router.rule, router.status)
asyncio.run(main())
Authentication
Traefik's API has no authentication of its own. It is normally protected by an
ipAllowList or a basicAuth middleware. For the second case, pass
credentials:
TraefikClient("https://traefik.example.com", username="admin", password="…")
For the first, the host running this code has to be inside the allowed range —
there is nothing the client can do about it. Either way a refusal raises
TraefikAuthenticationError.
Metrics
Traefik's Prometheus exporter usually lives on its own entrypoint, on a different port from the API, so it is configured separately and is off unless you ask for it:
client = TraefikClient(
"http://192.0.2.10:8080",
metrics_url="http://192.0.2.10:8082",
)
metrics = await client.get_metrics()
print(metrics.open_connections)
print(metrics.last_reload)
for cert in metrics.certificates:
print(cert.common_name, cert.days_remaining, "days left")
Only four metric families are read — open connections, config reloads, last successful reload, and per-certificate expiry. The rest of Traefik's output is per-route latency histograms and is skipped.
A note on serverStatus
Service.all_servers_up returns None, not True, when Traefik is not
probing a service's backends. Traefik only marks a server down when the
configuration gives that service a loadBalancer.healthCheck; without one it
reports every server as up forever, including servers that are switched off.
Note that a populated serverStatus is not evidence of probing — Traefik
fills it in either way. Service.has_health_check reads the service's
loadBalancer.healthCheck instead, which is the only honest signal.
Errors
All of them derive from TraefikError:
| Error | Meaning |
|---|---|
TraefikConnectionError |
Could not reach the instance |
TraefikAuthenticationError |
401/403 — allowlist or credentials |
TraefikNotFoundError |
The endpoint does not exist here |
TraefikResponseError |
The answer was not usable |
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file traefik-1.1.0.tar.gz.
File metadata
- Download URL: traefik-1.1.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2af5dd77d651e5bb4e39293cb580cba045bd07569f308b46fa6d82293d8552f3
|
|
| MD5 |
32d9cdcdf60f5c40ff678986cb231564
|
|
| BLAKE2b-256 |
492356f5d0360413d65d1ab769ada199703f69af021cc8e1037488c5f7b91759
|
File details
Details for the file traefik-1.1.0-py3-none-any.whl.
File metadata
- Download URL: traefik-1.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b190d72277bf847cdcedde0db45f67e2e025c52db8cc4d555a9517aced2ceb1
|
|
| MD5 |
9e5ba466d2e3b996d204cb96104dc238
|
|
| BLAKE2b-256 |
ba72fda817ff200b0e045b194ef0710dcdd756870d1687a47607ca09e3328f18
|