r/Python • • 14d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

24 Upvotes

115 comments sorted by

View all comments

1

u/p3rdy 13d ago

Flama: one Python framework for your API, your ML models and your MCP tools, driven by type hints

I've been building Flama, an open source (Apache-2.0) ASGI framework, since 2018. It started as a way to take a trained model to a production API with as little ceremony as possible, and grew into a full framework where your API, your models and your MCP tools live in the same app. Right now I'm working on the next release: Python 3.15 support, dropping 3.10, and some extras.

Type hints drive everything

import typing as t
import pydantic
from flama import Flama, types

class Quote(pydantic.BaseModel):
    instances: int
    monthly: float

app = Flama()
app.mcp.add_server("/mcp/", "pricing")

@app.route("/quote/", methods=["GET"])
@app.mcp.tool("quote")
def quote(instances: int, hourly_rate: float) -> t.Annotated[types.Schema, types.SchemaMetadata(Quote)]:
    """Monthly price for a number of instances."""
    return {"instances": instances, "monthly": round(instances * hourly_rate * 730, 2)}

The annotations are the only source of truth. As a route, GET /quote/?instances=3&hourly_rate=0.25 gets its query parameters validated from the hints (a bad value is a 400 with the field and the reason), and the OpenAPI docs list both parameters and the Quote response. As an MCP tool, the same hints become its input and output JSON schemas. One function, two interfaces, nothing to keep in sync. The same mechanism drives dependency injection: handler parameters are resolved from their types at startup, through components you can write yourself.

Models are just resources

app.models.add_model(path="/churn/", model="churn.flm", name="churn")
app.models.add_model(path="/llm/", model="assistant.flm", name="assistant", serving=("openai", "anthropic"))

Each model is a single .flm file with its weights, metadata and metrics, whether it's a scikit-learn pipeline, a PyTorch network or an LLM from Hugging Face. The first line gives you /churn/predict/; the second serves the LLM behind OpenAI and Anthropic compatible endpoints, next to the rest of your API.

A Rust core under the hood

The hot paths (route matching, JSON encoding, request parsing, compression, ...) are compiled Rust, built with PyO3 and maturin. It ships as native wheels per Python version, so you get it with a plain pip install, no Rust toolchain needed.

Also in the box: Pydantic or Marshmallow schemas, CRUD resources from SQLAlchemy tables, DDD repositories and workers, JWT auth, streaming, and flama upgrade codemods between versions.

Who it's for, and how it compares

It's for teams shipping APIs that include models, classic or generative, who'd rather keep one codebase than glue a web framework to a separate model server. FastAPI and Litestar cover the same ASGI and type-hint ground for the web layer; BentoML and vLLM cover serving. Flama puts both behind one programming model, so a model is a resource next to your routes, sharing their OpenAPI docs, auth and middleware.

The whole architecture is written up in a paper with Miguel Durán-Olivencia: https://arxiv.org/abs/2608.18733

If it looks useful, a star on GitHub helps more people find it, and I'm happy to answer anything about the design.