StarMallow
StarMallow is a starlette based web framework for building robust APIs with Python and Marshmallow. It's been inspired by FastAPI, but uses Marshmallow instead of Pydantic for it's schema definitions. It's reason for existing is simply because marshmallow is a much more powerful serialization engine, and in most cases it's fast enough. An example of Pydantic's limitations can be found in Issue 2277
Example
Create it
Create a file main.py with:
from typing import Annotated
from marshmallow_dataclass2 import dataclass
from starmallow import Body, Path, StarMallow
app = StarMallow()
# Minimum example
@app.get("/path/{item_id}")
def get_id(item_id):
return item_id
# Example with explicit location option
@dataclass
class MyBody:
item_id: int
sub_item_id: int
@app.get("/body")
async def get_body(body: MyBody = Body()) -> int:
return body.item_id
# Example with explicit marshmallow schema
class MyBodySchema(ma.Schema):
item_id = mf.Integer()
@app.get("/path/body_schema")
def get_body_from_schema(body: Dict[str, int] = Body(model=MyBodySchema)) -> int:
return body['item_id']
# Example with Annotated
@app.get("/body_annotated")
async def get_body_annotated(body: Annotated[MyBody, Body()]) -> int:
return body.item_id
Run it
Run the server with:
❯ uvicorn sample_server:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [84092]
INFO: Started server process [87944]
INFO: Waiting for application startup.
INFO: Application startup complete.
View the docs
- Open the browser at http://localhost:8000/docs to view the Swagger UI.
- Open the browser at http://localhost:8000/redoc to view the Redoc UI.
HTTP Endpoints
You can also use class-based views. This can make it easier to organize your code and gives you an easy migration path if you use flask-smorest
from marshmallow_dataclass2 import dataclass
from starmallow import StarMallow
from starmallow.decorators import route
from starmallow.endpoints import APIHTTPEndpoint
app = StarMallow()
@dataclass
class Pet:
name: str
@app.api_route('/')
class Pets(APIHTTPEndpoint):
def get(self) -> Pet:
return Pet.get()
def post(self, pet: Pet) -> Pet:
pet.create()
return pet
@app.api_route('/id/{pet_id}')
class PetById(ApiHttpEndpoint):
@route(deprecated=True) # Specify @route if you need to override parameters
def get(self, pet_id: int) -> Pet:
return Pet.get(pet_id)
@route(status_code=204) # Specify @route if you need to override parameters
def get(self, pet_id: int):
Pet.get(pet_id).delete()
Optional Dependencies
Metadata
Release files for starmallow 0.9.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| starmallow-0.9.4.tar.gz | 141.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starmallow-0.9.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 200.7 kB
Release files / starmallow-0.9.4.tar.gz
| Download URL | starmallow-0.9.4.tar.gz |
|---|---|
| Size | 141.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
936b0312ea62e2dc1e8c102884d5fa25cd3f9d088a5a02b1cbb145f822d9f549
|
|
BLAKE2b-256 checksum How to use checksums |
3a419a014fd7c6f08d082ca4f7130e6b700a16f2265606b187eaa62f901c5472
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / starmallow-0.9.4-py3-none-any.whl
| Download URL | starmallow-0.9.4-py3-none-any.whl |
|---|---|
| Size | 59.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f9d5cf0d1a4ab6fa64193111bff24131ed501a739d800a7e9da1d14e0db6cb0
|
|
BLAKE2b-256 checksum How to use checksums |
3685f2e746b3500cad8a313a0512512a723a576ea31e053771afa6bd8afd57b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|