Skip to main content

mlproxy-py

PyPI Python Versions License GitHub stars Downloads

mlproxy-py is a minimal ML inference reverse proxy with QoS-aware routing.

Designed for LLM / ML inference workloads where routing decisions should be based on latency, SLA targets, backend health, queue depth, and batching potential.

Features

  • Reverse proxy for JSON inference requests
  • Backends grouped into model pools
  • SLA-aware routing (choose lowest latency backend)
  • Optional micro-batching (collect requests for N ms)
  • Concurrent health checks with connection pooling
  • Prometheus metrics (request count, latency, backend latency)

Quickstart

Install

pip install mlproxy-py

Run proxy

mlproxy run -c examples/config.yml

Send request

curl -X POST http://localhost:7000/infer/modelA \
  -H "Content-Type: application/json" \
  -d '{"text":"hello"}'

Architecture

Client ──POST /infer/{model}──► FastAPI
                                    │
                          ┌─────────▼──────────┐
                          │  ModelRouter       │
                          │  choose_backend()  │
                          │  (score = latency  │
                          │   + active_req*5)  │
                          └─────────┬──────────┘
                                    │ backend URL
                          ┌─────────▼──────────┐
                          │  forward_json()    │
                          │  (httpx conn pool) │
                          └─────────┬──────────┘
                                    ▼
                            Backend ML server

       ┌──────────────────┐    ┌──────────────────┐
       │  BatchQueue      │    │  Healthcheck     │
       │  (optional per   │    │  (concurrent,    │
       │   model pool)    │    │   per-backend)   │
       └──────────────────┘    └──────────────────┘

Config

See examples/config.yml.

Changelog

0.1.1

  • Lifespan pattern: Migrated from deprecated @app.on_event("startup") to FastAPI lifespan context manager.
  • Graceful shutdown: Batch workers and healthcheck loop are properly cancelled on shutdown.
  • Connection pooling: Shared httpx.AsyncClient singletons for proxy and healthcheck (was creating a client per request/check).
  • Concurrent health checks: Backends checked in parallel via asyncio.gather (was sequential).
  • Logging: Added structured logging throughout; --log-level CLI option.
  • Bare except fixes: All except Exception blocks re-raise asyncio.CancelledError.
  • Deprecated API fixes: Replaced asyncio.get_event_loop() with asyncio.get_running_loop() in batching module.
  • Build system: Migrated from setuptools to hatchling. Added classifiers, keywords, optional dev/test deps, ruff/pytest config.
  • Tests: Expanded from 1 test to 15+ tests covering config, router, batching, proxy, healthcheck, and backends.

0.1.0

  • Initial release: JSON inference proxy, model pools, SLA-aware routing, micro-batching, health checks, Prometheus metrics.

License

MIT

Metadata

Release files for mlproxy-py 0.1.1

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

Source distribution (sdist)

Source distribution for mlproxy-py 0.1.1
File Size Uploaded Provenance Actions
mlproxy_py-0.1.1.tar.gz 10.9 kB Without provenance Details for mlproxy_py-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mlproxy-py 0.1.1
File Interpreter ABI Platform Actions
mlproxy_py-0.1.1-py3-none-any.whl Python 3 none any Details for mlproxy_py-0.1.1-py3-none-any.whl

Total release size: 21.7 kB

Release files / mlproxy_py-0.1.1.tar.gz

Download URL mlproxy_py-0.1.1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f7e46458f8e6784aeb9b6eca66a18917142d482e42c724449583622146544a75
BLAKE2b-256 checksum
How to use checksums
6075eab5d2b9c807832afa51a197fd6c60347efae7c50233ec265b20d45ebb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / mlproxy_py-0.1.1-py3-none-any.whl

Download URL mlproxy_py-0.1.1-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1462ec15c8c6a32b52055dd2001b6d529d43eb7e4325c38d2a2d6b1f574d11fa
BLAKE2b-256 checksum
How to use checksums
65838f1246c756fedacb0dccd34e62f4c92d9b2b8ad10ca5a77ba0abce8db6f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for mlproxy-py 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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