Skip to main content

python-traefik

A production-grade, Traefik-inspired reverse proxy implemented in Python using asyncio and Starlette.

PyPI Python 3.10+ License: MIT CI Ruff

Demo

python-traefik demo

Features

Core (Implemented ✔)

  • Dynamic Routing — rule-based routing with Host(), PathPrefix(), Path(), HostRegexp(), Headers(), Method(), ClientIP() matchers
  • Compound Rules — combine matchers with &&, ||, and parentheses: (Host(\a.com`) || Host(`b.com`)) && PathPrefix(`/api`)`
  • Load Balancing — round-robin across backend servers with health-aware selection
  • Health Checks — periodic async health probes; unhealthy backends are automatically removed from rotation
  • Prometheus Metrics — request count and latency histograms at /metrics
  • Reverse Proxy — full HTTP forwarding with hop-by-hop header filtering and X-Forwarded-* injection
  • Connection Pooling — shared httpx.AsyncClient for efficient backend connections

Middleware Pipeline ✔

  • Rate Limiting — per-IP token bucket rate limiter
  • Basic Auth — HTTP Basic authentication
  • Circuit Breaker — trips open after N failures, auto-recovers after timeout
  • Retry — configurable retry with exponential back-off
  • Headers — set, add, or remove response headers
  • Redirect Scheme — HTTP → HTTPS redirect

TCP/UDP Support ✔

  • TCP Proxy — layer-4 TCP reverse proxy with bidirectional streaming
  • UDP Proxy — layer-4 UDP relay with client address tracking
  • TLS Termination — optional TLS on TCP entrypoints

SSL/TLS Certificate Management ✔

  • Static Certificates — load PEM cert/key from files
  • Self-Signed Generation — auto-generate dev certs via cryptography
  • ACME Stub — provisioning framework (full Let's Encrypt client TBD)
  • Certificate Store — in-memory store with wildcard domain support

Service Discovery ✔

  • Consul — discover services from Consul catalog with health filtering
  • Kubernetes — discover services from K8s API with in-cluster token auto-detection
  • Hot Reload — discovered services update the registry without restart

Dashboard API ✔

  • Web UI — dark-themed dashboard at /dashboard
  • REST API — JSON endpoints for overview, routers, services, and certificates
  • Real-time Status — backend health status with visual indicators

Architecture

┌──────────────┐     ┌──────────────┐     ┌──────────────┐
│  Entrypoint  │────▶│    Router    │────▶│  Middleware   │
│  :8000 HTTP  │     │  Rule Match  │     │   Pipeline   │
│  :3306 TCP   │     │  Priority    │     │  rate-limit  │
│  :5353 UDP   │     │              │     │  basic-auth  │
└──────────────┘     └──────────────┘     │  retry       │
                                          └──────┬───────┘
                                                 │
                     ┌──────────────┐     ┌──────▼───────┐
                     │   Backend    │◀────│ Load Balancer│
                     │  :5000       │     │ Round-Robin  │
                     │  :5001       │     │ Health-Aware │
                     └──────────────┘     └──────────────┘

Quickstart

Install

pip install -e .

Install with dev dependencies

pip install -e ".[dev]"

Run

python-traefik run --config examples/config.yml

Validate config without starting

python-traefik validate --config examples/config.yml

Check version

python-traefik version

Test routing

# Route by host
curl -H "Host: example.com" http://localhost:8000/

# Prometheus metrics
curl http://localhost:8000/metrics

# Dashboard
open http://localhost:8080/dashboard

# Dashboard API
curl http://localhost:8080/api/overview
curl http://localhost:8080/api/routers
curl http://localhost:8080/api/services

Configuration

See examples/config.yml for a basic setup and examples/config_full.yml for a full reference.

Minimal Config

entryPoints:
  web:
    address: ":8000"

routers:
  app:
    rule: "Host(`example.com`) && PathPrefix(`/`)"
    service: "app_service"

services:
  app_service:
    loadBalancer:
      servers:
        - url: "http://localhost:5000"

Config Sections

Section Description
entryPoints HTTP listener addresses
tcpEntryPoints TCP proxy listeners
udpEntryPoints UDP proxy listeners
routers Rule → service mapping with optional middlewares and priority
services Backend server groups with load balancer
middlewares Named middleware definitions
tls TLS certificates and ACME configuration
metrics Prometheus endpoint toggle
healthcheck Backend health probe settings
dashboard Dashboard UI and API
providers Service discovery (Consul, Kubernetes)
logging Log level and access log toggle

Development

Run tests

pytest tests/ -v

Lint

ruff check python_traefik/

License

MIT — see LICENSE.

Metadata

Release files for python-traefik 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-traefik 0.4.0
File Size Uploaded Provenance Actions
python_traefik-0.4.0.tar.gz 32.2 kB Without provenance Details for python_traefik-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-traefik 0.4.0
File Interpreter ABI Platform Actions
python_traefik-0.4.0-py3-none-any.whl Python 3 none any Details for python_traefik-0.4.0-py3-none-any.whl

Total release size: 61.6 kB

Release files / python_traefik-0.4.0.tar.gz

Download URL python_traefik-0.4.0.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
22f71d455ff2d528b9462d4bea5eefade0d45f3a8f4a1b8a1025128f34df32dd
BLAKE2b-256 checksum
How to use checksums
e014b795b741d61102e25a7f725c815f189c508181d34aa75dcca82949a2dc2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / python_traefik-0.4.0-py3-none-any.whl

Download URL python_traefik-0.4.0-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d969925b77bc3f8b4658647afda39e9a893e40bc39eff4da8b1972bbafecf403
BLAKE2b-256 checksum
How to use checksums
779cbe2de30f6a1339518fb225565d23e237bbfb7da433bd8234124df8b0fb55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for python-traefik 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page