Skip to main content

FastAPI-like router for Starlette with msgspec integration

Project description

starlette-msgspec

A FastAPI-like router for Starlette with msgspec integration for automatic request validation and OpenAPI documentation.

Installation

# Install with pip
pip install starlette-msgspec

# Or with uv
uv pip install starlette-msgspec

# For development on this library
uv sync --dev

Usage

from starlette.applications import Starlette
from starlette_msgspec import MsgspecRouter, add_openapi_routes
import msgspec
from typing import List


# Define your data model with msgspec
class Item(msgspec.Struct):
    name: str
    description: str = ""
    price: float
    tax: float = 0.0


app = Starlette()
router = MsgspecRouter()


@router.post("/items", tags=["items"])
async def create_item(body: Item):
    return body


@router.get("/items", tags=["items"])
async def get_items() -> List[Item]:
    # ... implementation
    return [Item(name="Example", price=10.5)]


# Include the router and add OpenAPI documentation routes
router.include_router(app)
add_openapi_routes(app, router)

💡 For a more comprehensive example showing multiple routers, different data models, and advanced features, check out examples/basic_app.py.

Features

  • FastAPI-like router with method, path, and tags
  • Automatic request validation based on msgspec types
  • OpenAPI documentation generation using msgspec's built-in schema capabilities
  • Type annotations for request body and response

Running the example

# Install dependencies
uv sync --dev

# Run the example
uv run examples/basic_app.py

Then visit http://localhost:8000/docs to see the Swagger UI documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_msgspec-0.2.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starlette_msgspec-0.2.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file starlette_msgspec-0.2.0.tar.gz.

File metadata

  • Download URL: starlette_msgspec-0.2.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.15

File hashes

Hashes for starlette_msgspec-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6d831e76bd359431ac3a0ca3c6a1f63890b642c7966132cd0f32e7369adb819e
MD5 bb12b2bedf13f53083531f52216cba1c
BLAKE2b-256 d02b581512d649b4a0139c309cfab5ada36a9785e55e671db7d887b9c1f3aad9

See more details on using hashes here.

File details

Details for the file starlette_msgspec-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for starlette_msgspec-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01a7c9761079ffd65080a27d0a81367e64ed61531c092d4cdd7bb2dc60ee2641
MD5 a2baa52053cf36c450d74ccecefaee3e
BLAKE2b-256 a15cdad12a398817175b87aa9660c1bd62744763f480bdca5a516b6fb2bbf3bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page