Muffin‑REST simplifies building RESTful APIs with Muffin by offering:
- Declarative
API
class with resource registration - Built-in filtering, sorting, pagination, and search
- Support for:
- Peewee ORM via
PeeweeEndpoint
- SQLAlchemy Core via
SAEndpoint
- MongoDB via
MongoEndpoint
- Peewee ORM via
- Swagger/OpenAPI autodocumentation
- Works with asyncio, Trio, and Curio
- Python >= 3.10
- Trio requires Peewee backend
Install core package:
pip install muffin-rest
Add optional backend support:
- SQLAlchemy Core:
pip install muffin-rest[sqlalchemy]
- Peewee ORM:
pip install muffin-rest[peewee]
- YAML support for Swagger:
pip install muffin-rest[yaml]
from muffin import Application
from muffin_rest import API
from muffin_rest.peewee import PeeweeEndpoint
from models import User # your Peewee model
app = Application("myapp")
api = API(title="User Service", version="1.0")
@api.route
class UsersEndpoint(PeeweeEndpoint):
class Meta:
model = User
lookup_field = "id"
filters = ["name", "email"]
ordering = ["-created_at"]
api.setup(app, prefix="/api", swagger=True)
Endpoints available:
GET /api/users/
— list with pagination, search, filteringPOST /api/users/
— createGET /api/users/{id}/
— retrievePUT /api/users/{id}/
— replacePATCH /api/users/{id}/
— updateDELETE /api/users/{id}/
— remove- Docs:
/api/docs/
, OpenAPI spec:/api/openapi.json
from muffin_rest import API
from muffin_rest.sqlalchemy import SAEndpoint
from models import my_table, db_engine
api = API()
@api.route
class MySAEndpoint(SAEndpoint):
class Meta:
table = my_table
database = db_engine
api.setup(app)
from muffin_rest import API
from muffin_rest.mongo import MongoEndpoint
from models import mongo_collection
api = API()
@api.route
class MyMongoEndpoint(MongoEndpoint):
class Meta:
collection = mongo_collection
api.setup(app)
Customize Swagger and routes via constructor:
api = API(
title="Service API",
version="2.1",
swagger_ui=True,
openapi_path="/api/openapi.json",
docs_path="/api/docs/"
)
- See
examples/
for live application demos - Tests in
tests/
focus on filtering, pagination, status codes - Check
CHANGELOG.md
for latest changes
Report bugs or request features: https://github.com/klen/muffin-rest/issues
Repo: https://github.com/klen/muffin-rest Pull requests, example additions, docs improvements welcome!
- klen (Kirill Klenov)
Licensed under the MIT license.