Skip to main content

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.

Metadata

Release files for starlette-msgspec 0.6.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 starlette-msgspec 0.6.0
File Size Uploaded Provenance Actions
starlette_msgspec-0.6.0.tar.gz 10.0 kB Without provenance Details for starlette_msgspec-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for starlette-msgspec 0.6.0
File Interpreter ABI Platform Actions
starlette_msgspec-0.6.0-py3-none-any.whl Python 3 none any Details for starlette_msgspec-0.6.0-py3-none-any.whl

Total release size: 18.0 kB

Release files / starlette_msgspec-0.6.0.tar.gz

Download URL starlette_msgspec-0.6.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a554c081f73683699fca43f7e9bc8d36bf749bd7fa57f5e8e2b9df6ebe82faa7
BLAKE2b-256 checksum
How to use checksums
d6e7861539b17c6062aee680ea1806a9968665bffc4bbdef1144abae5cd1d0a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / starlette_msgspec-0.6.0-py3-none-any.whl

Download URL starlette_msgspec-0.6.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51be290e3bc1f3abd95b79c46fdf6f61703d92ee1d9785e10a90b27df85f42c8
BLAKE2b-256 checksum
How to use checksums
53e3a51f0ef84e6507f16e67bbb8528beef4ae016dafca7749b42429fcea646c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Security for starlette-msgspec 0.6.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.

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