FastAPI Integration

Native TOON response class for FastAPI endpoints.

Installation

pip install toonverter[fastapi]

Basic Usage

from fastapi import FastAPI
from toonverter.integrations import TOONResponse

app = FastAPI()

@app.get("/users", response_class=TOONResponse)
async def get_users():
    return {
        "users": [
            {"name": "Alice", "age": 30},
            {"name": "Bob", "age": 25}
        ],
        "count": 2
    }

Response Automatically

The response is automatically serialized as TOON with proper content-type header.

Token Savings

# JSON response: ~120 characters
# TOON response: ~60 characters (50% savings)
# Perfect for mobile/low-bandwidth clients

Use Cases

  • Efficient API responses

  • Mobile-first applications

  • Token-conscious LLM applications

  • High-traffic endpoints

See Also