Name | starmallow JSON |
Version |
0.6.3
JSON |
| download |
home_page | None |
Summary | StarMallow framework |
upload_time | 2024-12-08 01:45:52 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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](https://marshmallow.readthedocs.io/en/stable/) instead of [Pydantic](https://docs.pydantic.dev/) 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](https://github.com/pydantic/pydantic/issues/2277)
## Example
### Create it
Create a file `main.py` with:
```python
from typing import Annotated
from marshmallow_dataclass 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:
```shell
❯ 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](http://localhost:8000/docs) to view the Swagger UI.
* Open the browser at [http://localhost:8000/redoc](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](https://flask-smorest.readthedocs.io/)
```python
from marshmallow_dataclass 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
* [`uvicorn`](https://www.uvicorn.org) - for the server that loads and serves your application.
* [`orjson`](https://github.com/ijl/orjson) - Required if you want to use `ORJSONResponse`.
* [`ujson`](https://github.com/esnme/ultrajson) - Required if you want to use `UJSONResponse`.
Raw data
{
"_id": null,
"home_page": null,
"name": "starmallow",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Michiel Vanderlee <jmt.vanderlee@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a5/ce/3e11b47eb7fe59004dd485203f33671590570e51a47776ed9965050c6a60/starmallow-0.6.3.tar.gz",
"platform": null,
"description": "# StarMallow\n\nStarMallow is a starlette based web framework for building robust APIs with Python and Marshmallow.\nIt's been inspired by FastAPI, but uses [Marshmallow](https://marshmallow.readthedocs.io/en/stable/) instead of [Pydantic](https://docs.pydantic.dev/) for it's schema definitions.\nIt's reason for existing is simply because marshmallow is a much more powerful serialization engine, and in most cases it's fast enough.\nAn example of Pydantic's limitations can be found in [Issue 2277](https://github.com/pydantic/pydantic/issues/2277)\n\n## Example\n\n### Create it\n\nCreate a file `main.py` with:\n\n```python\nfrom typing import Annotated\nfrom marshmallow_dataclass import dataclass\nfrom starmallow import Body, Path, StarMallow\n\napp = StarMallow()\n\n# Minimum example\n@app.get(\"/path/{item_id}\")\ndef get_id(item_id):\n return item_id\n\n\n# Example with explicit location option\n@dataclass\nclass MyBody:\n item_id: int\n sub_item_id: int\n\n\n@app.get(\"/body\")\nasync def get_body(body: MyBody = Body()) -> int:\n return body.item_id\n\n\n# Example with explicit marshmallow schema\nclass MyBodySchema(ma.Schema):\n item_id = mf.Integer()\n\n@app.get(\"/path/body_schema\")\ndef get_body_from_schema(body: Dict[str, int] = Body(model=MyBodySchema)) -> int:\n return body['item_id']\n\n\n# Example with Annotated\n\n@app.get(\"/body_annotated\")\nasync def get_body_annotated(body: Annotated[MyBody, Body()]) -> int:\n return body.item_id\n```\n\n### Run it\n\nRun the server with:\n\n```shell\n\u276f uvicorn sample_server:app --reload\n\nINFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\nINFO: Started reloader process [84092]\nINFO: Started server process [87944]\nINFO: Waiting for application startup.\nINFO: Application startup complete.\n```\n\n### View the docs\n\n* Open the browser at [http://localhost:8000/docs](http://localhost:8000/docs) to view the Swagger UI.\n* Open the browser at [http://localhost:8000/redoc](http://localhost:8000/redoc) to view the Redoc UI.\n\n## HTTP Endpoints\n\nYou 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](https://flask-smorest.readthedocs.io/)\n\n```python\nfrom marshmallow_dataclass import dataclass\nfrom starmallow import StarMallow\nfrom starmallow.decorators import route\nfrom starmallow.endpoints import APIHTTPEndpoint\n\n\napp = StarMallow()\n\n\n@dataclass\nclass Pet:\n name: str\n\n\n@app.api_route('/')\nclass Pets(APIHTTPEndpoint):\n def get(self) -> Pet:\n return Pet.get()\n\n def post(self, pet: Pet) -> Pet:\n pet.create()\n return pet\n\n\n@app.api_route('/id/{pet_id}')\nclass PetById(ApiHttpEndpoint):\n @route(deprecated=True) # Specify @route if you need to override parameters\n def get(self, pet_id: int) -> Pet:\n return Pet.get(pet_id)\n\n\n @route(status_code=204) # Specify @route if you need to override parameters\n def get(self, pet_id: int):\n Pet.get(pet_id).delete()\n```\n\n## Optional Dependencies\n\n* [`uvicorn`](https://www.uvicorn.org) - for the server that loads and serves your application.\n* [`orjson`](https://github.com/ijl/orjson) - Required if you want to use `ORJSONResponse`.\n* [`ujson`](https://github.com/esnme/ultrajson) - Required if you want to use `UJSONResponse`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "StarMallow framework",
"version": "0.6.3",
"project_urls": {
"Homepage": "https://github.com/mvanderlee/starmallow"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "55e2a246c34134ffdc685cb25e8c2900ce800874ce4a9a1acfca0777b184702a",
"md5": "29ecbb2e896d28d47729b9d5e93e5486",
"sha256": "50c5238f5096653d44f2af9e295786a88fc0c9fb94a7c048de18d0ab65269928"
},
"downloads": -1,
"filename": "starmallow-0.6.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "29ecbb2e896d28d47729b9d5e93e5486",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 56099,
"upload_time": "2024-12-08T01:45:50",
"upload_time_iso_8601": "2024-12-08T01:45:50.546942Z",
"url": "https://files.pythonhosted.org/packages/55/e2/a246c34134ffdc685cb25e8c2900ce800874ce4a9a1acfca0777b184702a/starmallow-0.6.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a5ce3e11b47eb7fe59004dd485203f33671590570e51a47776ed9965050c6a60",
"md5": "1f8d21310ae340bad7a8d9b711200714",
"sha256": "9bf894cbe61c1908b32febf1a5330a900b6e9643359de19193c2393e5f4dc81e"
},
"downloads": -1,
"filename": "starmallow-0.6.3.tar.gz",
"has_sig": false,
"md5_digest": "1f8d21310ae340bad7a8d9b711200714",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 80570,
"upload_time": "2024-12-08T01:45:52",
"upload_time_iso_8601": "2024-12-08T01:45:52.446560Z",
"url": "https://files.pythonhosted.org/packages/a5/ce/3e11b47eb7fe59004dd485203f33671590570e51a47776ed9965050c6a60/starmallow-0.6.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-08 01:45:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mvanderlee",
"github_project": "starmallow",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "starmallow"
}