Skip to main content

Provider/plugin framework for dynamic reverse proxy configuration (Traefik-like providers in Python).

Project description

python-proxy-provider

PyPI Python Versions License GitHub stars Downloads

A Traefik-like provider framework for dynamic proxy configuration in Python.

This project is not a full reverse proxy by itself. It is a provider engine that watches multiple sources (files, HTTP APIs, Docker, Consul, etc.) and produces a normalized routing configuration.

Use cases

  • Build a Python Traefik-like router
  • Build an edge gateway that reloads routes dynamically
  • Implement Kubernetes/Docker providers in Python
  • Provide unified routing config for multiple systems

Features

  • Provider plugin interface (ProviderBase) with start() / stop() / current_config()
  • Provider manager — loads providers, merges configs, tracks background tasks
  • File provider — watches YAML files for live changes via watchfiles
  • HTTP provider — polls JSON routes from a remote endpoint with connection pooling
  • Event bus — async pub/sub for config update notifications
  • Graceful shutdown — signal handlers (SIGINT/SIGTERM) stop all providers cleanly
  • Configurable logging--log-level CLI option (DEBUG, INFO, WARNING, ERROR)
  • Merge conflict detection — logs warnings when multiple providers define the same router or service

Quickstart

Install

pip install python-proxy-provider

Run demo

proxy-provider run --file examples/routes.yml

Then edit examples/routes.yml and see live reload output.

Combine multiple providers:

proxy-provider run --file examples/routes.yml --http http://localhost:8000/routes --log-level DEBUG

Architecture

                    ┌─────────────────┐
                    │   EventBus      │
                    │  (async Queue)  │
                    └──────┬──────────┘
          ┌────────────────┼────────────────┐
          ▼                ▼                ▼
   FileProvider      HttpProvider     (future providers)
   (watch YAML)     (poll JSON)       Docker, Consul, K8s
          │                │                │
          └────────────────┼────────────────┘
                           ▼
                    ProviderManager
                    ┌──────────┐
                    │  merge() │
                    └────┬─────┘
                         ▼
                   DynamicConfig
              (routers + services)

Provider API

Implement a custom provider by subclassing ProviderBase:

from python_proxy_provider.providers.base import ProviderBase
from python_proxy_provider.models import DynamicConfig
from python_proxy_provider.events import ConfigEvent

class MyProvider(ProviderBase):
    name = "my"

    async def start(self):
        cfg = DynamicConfig(...)
        await self.bus.publish(ConfigEvent(provider=self.name, config=cfg))

    async def current_config(self) -> DynamicConfig:
        return self._config

Roadmap

  • Docker provider (watch containers)
  • Consul provider
  • Kubernetes provider
  • Plugin discovery via entry_points
  • Conflict resolution policies
  • Distributed config cache

Changelog

0.1.1

  • Graceful shutdown: Signal handlers (SIGINT/SIGTERM) stop all providers cleanly.
  • Connection pooling: Shared httpx.AsyncClient singleton (was creating a client per request).
  • Logging: Replaced print() with structured logging throughout; added --log-level CLI option.
  • Merge conflict detection: Warns when multiple providers define the same router/service key.
  • EventBus close: EventBus.close() prevents publishing after shutdown; subscribe loop exits cleanly.
  • Task tracking: ProviderBase tracks background task for proper cancellation via stop().
  • Bare except fixes: All except Exception blocks re-raise asyncio.CancelledError.
  • Build system: Migrated from setuptools to hatchling. Added classifiers, keywords, optional dev/test deps, ruff/pytest config.
  • Tests: Expanded from 1 test to 20 tests covering models, events, manager, file provider, and HTTP provider.

0.1.0

  • Initial release: Provider plugin interface, file provider, HTTP provider, event bus, CLI demo.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_proxy_provider-0.1.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_proxy_provider-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file python_proxy_provider-0.1.1.tar.gz.

File metadata

  • Download URL: python_proxy_provider-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for python_proxy_provider-0.1.1.tar.gz
Algorithm Hash digest
SHA256 567eb08f8eee48502069e771b534d8419c5f2afe034cf590260cc82f1fd8bd11
MD5 a24870386b25c8e33db96ce618d81e48
BLAKE2b-256 c540ac99dbedf21a444fbb09518dac540ccea5cafeccc32f950296a15a5048ea

See more details on using hashes here.

File details

Details for the file python_proxy_provider-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_proxy_provider-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80feb92e70e47ca3d2cc3f4fc0e8d365819a937af21ea7858c3bf19a211b956e
MD5 898a6ffcd4f6ee4742f7fdca43847136
BLAKE2b-256 4e505a83959438a5535500b9364ddf7d489bef719c417163bc3cf10032b0bb9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page