Skip to main content

JLServe

A simple Python framework for creating ML inference endpoints with minimal boilerplate.

Features

  • Simple API - Decorator-based pattern for defining apps and endpoints
  • Type-safe - Pydantic models for input/output validation
  • Developer-friendly - IDE autocomplete, typo detection, auto-generated docs
  • Fast startup - Server ready in under 2 seconds

Installation

pip install jlserve

Or with uv:

uv add jlserve

Quick Start

Create an app in app.py:

import jlserve
from pydantic import BaseModel


class Input(BaseModel):
    name: str


class Output(BaseModel):
    message: str


@jlserve.app()
class Greeter:
    def setup(self):
        self.prefix = "Hello"

    @jlserve.endpoint()
    def greet(self, input: Input) -> Output:
        return Output(message=f"{self.prefix}, {input.name}!")

Run the server:

jlserve dev app.py

Output:

Serving Greeter at http://localhost:8000
Docs at http://localhost:8000/docs

Endpoints: POST /greet

Test the endpoint:

curl -X POST http://localhost:8000/greet \
  -H "Content-Type: application/json" \
  -d '{"name": "World"}'

Response:

{"message": "Hello, World!"}

API Reference

@jlserve.app()

Decorator that marks a class as a JLServe app. Only one app per module/deployment.

Parameter Type Required Description
name str No Custom name for the app. Defaults to class name.
requirements list[str] No Python dependencies to auto-install (e.g., ["torch", "transformers"])

@jlserve.endpoint()

Decorator that marks a method as an endpoint within the app class.

Parameter Type Required Description
path str No Custom route path. Defaults to "/" + method name.

Class Methods

Method Required Description
setup(self) No Called once when server starts. Use for loading models, initializing resources.
<endpoint_method>(self, input) -> output Yes Endpoint methods decorated with @jlserve.endpoint(). Must have type hints for input and output.

Input/Output Requirements

  • Input must be a Pydantic BaseModel subclass
  • Output must be a Pydantic BaseModel subclass
  • Type hints are required on endpoint methods

CLI Reference

jlserve dev <file>

Runs the app locally for development.

Option Default Description
--port, -p 8000 Port to serve on

Example:

jlserve dev app.py --port 3000

Auto-Generated Features

Feature Description
OpenAPI docs Available at /docs
Request validation Invalid input returns 422 with details
JSON serialization Automatic based on Pydantic models

Error Handling

Error Behavior
No @jlserve.app() class Error at startup: "No app found. Did you decorate a class with @jlserve.app()?"
No endpoint methods Error at startup: "App has no endpoints. Add methods decorated with @jlserve.endpoint()."
Missing type hints on endpoint methods Error at startup: Validation error with details
Invalid input JSON 422 response with validation errors
Exception in endpoint method 500 response with error message
Exception in setup() Server fails to start with error message

Example: ML Inference

import jlserve
from pydantic import BaseModel


class SentimentInput(BaseModel):
    text: str


class SentimentOutput(BaseModel):
    label: str
    score: float


@jlserve.app(requirements=["transformers"])
class SentimentAnalyzer:
    def setup(self):
        from transformers import pipeline
        self.pipe = pipeline("sentiment-analysis")

    @jlserve.endpoint()
    def analyze(self, input: SentimentInput) -> SentimentOutput:
        result = self.pipe(input.text)[0]
        return SentimentOutput(
            label=result["label"],
            score=result["score"]
        )

Development

Run tests:

uv run pytest

License

MIT

Metadata

Release files for jlserve 0.1.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 jlserve 0.1.0
File Size Uploaded Provenance Actions
jlserve-0.1.0.tar.gz 54.0 kB Without provenance Details for jlserve-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jlserve 0.1.0
File Interpreter ABI Platform Actions
jlserve-0.1.0-py3-none-any.whl Python 3 none any Details for jlserve-0.1.0-py3-none-any.whl

Total release size: 76.3 kB

Release files / jlserve-0.1.0.tar.gz

Download URL jlserve-0.1.0.tar.gz
Size 54.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f202412449a696d26c884a9db2370f3e1551ac5d797718f7d3d5a124e4547e5c
BLAKE2b-256 checksum
How to use checksums
f3b0fd8314718823854c26c6d75b8cf6e19f893ce70f32cc89ed1171cf76e348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / jlserve-0.1.0-py3-none-any.whl

Download URL jlserve-0.1.0-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f66e28c8bd0c942e924e3a3be2b86e878a79004f2ad77a5c300991c05ac3410
BLAKE2b-256 checksum
How to use checksums
d38e944d36c0fd0cce7752870aee4faa8a668a0b7bb831850f57dff12ecb3747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Security for jlserve 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 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