Metadata-Version: 2.4
Name: servectl
Version: 0.2.0
Summary: Serve a model file over HTTP with health and Prometheus metrics.
Project-URL: Homepage, https://github.com/jmweb-org/servectl
Project-URL: Repository, https://github.com/jmweb-org/servectl
Project-URL: Issues, https://github.com/jmweb-org/servectl/issues
Author: José del Río
License: MIT License
        
        Copyright (c) 2026 José del Río
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: cli,fastapi,inference,mlops,model-serving,prometheus
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Requires-Dist: fastapi>=0.110
Requires-Dist: joblib>=1.3
Requires-Dist: numpy>=1.24
Requires-Dist: prometheus-client>=0.20
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.12
Requires-Dist: uvicorn>=0.29
Description-Content-Type: text/markdown

# servectl

[![CI](https://github.com/jmweb-org/servectl/actions/workflows/ci.yml/badge.svg)](https://github.com/jmweb-org/servectl/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/servectl.svg)](https://pypi.org/project/servectl/)
[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Serve a model file over HTTP in one command, with health and Prometheus metrics
built in.

You have a trained model on disk and you want it behind an HTTP endpoint to try
it, wire it into a demo, or scrape its metrics, without writing a FastAPI app
each time. `servectl` loads the artifact and serves it: a typed `/predict`, a
`/health` check, and a Prometheus `/metrics` endpoint, ready to scrape.

```console
$ servectl serve model.joblib --port 8000
servectl: serving 'model' on http://127.0.0.1:8000

$ curl -s localhost:8000/predict -d '{"instances": [[5.1, 3.5, 1.4, 0.2]]}'
{"predictions": [0]}
```

## Install

```console
$ pip install servectl                 # from PyPI, once released
$ pip install git+https://github.com/jmweb-org/servectl   # latest, available now
```

Loads any joblib/pickle artifact that exposes a scikit-learn-style `predict`
(and optionally `predict_proba`).

## Usage

```console
$ servectl serve model.joblib                 # serve on 127.0.0.1:8000
$ servectl serve model.joblib --host 0.0.0.0 --port 9000
$ servectl info model.joblib                  # inspect without serving
```

## Endpoints

| Method | Path | Purpose |
| --- | --- | --- |
| POST | `/predict` | `{"instances": [[...], ...]}` to `{"predictions": [...]}` |
| POST | `/predict_proba` | Class probabilities, if the model supports it |
| GET | `/health` | Model name, feature count and version |
| GET | `/metrics` | Prometheus exposition format |

The request body is validated: `instances` must be a non-empty list of equal-
length numeric rows. A bad request returns 400 with a message, not a stack
trace.

## Metrics

The `/metrics` endpoint exposes:

- `servectl_requests_total{endpoint, outcome}` — request count per endpoint and ok/error.
- `servectl_predictions_total` — total prediction instances served.
- `servectl_predict_seconds` — prediction latency histogram.

Each server uses its own registry, so the counters reflect only that process.

### Prometheus scrape example

If `servectl` is running on port 8000, add a scrape job like this to
`prometheus.yml`:

```yaml
scrape_configs:
  - job_name: "servectl"
    metrics_path: "/metrics"
    static_configs:
      - targets: ["localhost:8000"]
```

For multiple model servers, give each target a stable label so dashboards can
separate them:

```yaml
scrape_configs:
  - job_name: "servectl"
    metrics_path: "/metrics"
    static_configs:
      - targets: ["iris-api:8000"]
        labels:
          model: "iris"
      - targets: ["churn-api:8000"]
        labels:
          model: "churn"
```

### Grafana panel queries

Use these PromQL queries for a basic dashboard:

| Panel | PromQL |
| --- | --- |
| Request rate | `sum by (endpoint, outcome) (rate(servectl_requests_total[5m]))` |
| Prediction throughput | `rate(servectl_predictions_total[5m])` |
| p95 prediction latency | `histogram_quantile(0.95, sum by (le) (rate(servectl_predict_seconds_bucket[5m])))` |

For per-model latency when you added a `model` scrape label, group the histogram
by both `model` and `le`:

```promql
histogram_quantile(
  0.95,
  sum by (model, le) (rate(servectl_predict_seconds_bucket[5m]))
)
```

## Scope

`servectl` is for trying a model, demos, and internal services. It does no
authentication, batching, or autoscaling. For a hardened deployment, put it
behind a reverse proxy or use a full serving stack; for a quick, observable
endpoint from a model file, this is one command.

## License

MIT. See [LICENSE](LICENSE).
