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.register_routes(app)
add_openapi_routes(app)

💡 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.4.2.tar.gz (9.5 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.4.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for starlette_msgspec-0.4.2.tar.gz
Algorithm Hash digest
SHA256 d9233602c7135e3bde2e22d97f53515ed47b733c57e4e5b158ef4a9c508228cb
MD5 1eaa4b2d669da8819066bee883394dd2
BLAKE2b-256 23862e4ad2d16152359131a4b9451b586e5963370e2b1cb9b7762c6a351a6c5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for starlette_msgspec-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec44cf73477f90f39b16088666a983e588b4bf09bd21180f48e7e010dbba896a
MD5 333a4b541ded3ca45d34fc95ba55dd55
BLAKE2b-256 09acb6f912e9326207959c54f3fa83f0887c4bd3cd3769da0284cfb996d7d4ce

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