Batteries included framework for generating RESTful apis using Flask and SqlAlchemy.
Project description
Flask-Muck
With Flask-Muck you don't have to worry about the CRUD.
Flask-Muck is a batteries-included framework for automatically generating RESTful APIs with Create, Read, Update and Delete (CRUD) endpoints in a Flask/SqlAlchemy application stack.
from flask import Blueprint
from flask_muck.views import FlaskMuckApiView
import marshmallow as ma
from marshmallow import fields as mf
from myapp import db
class MyModel(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
class MyModelSchema(ma.Schema):
id = mf.Integer(dump_only=True)
name = mf.String()
class MyModelApiView(FlaskMuckApiView):
api_name = "my-model"
session = db.session
Model = MyModel
ResponseSchema = MyModelSchema
CreateSchema = MyModelSchema
PatchSchema = MyModelSchema
UpdateSchema = MyModelSchema
searchable_columns = [MyModel.name]
blueprint = Blueprint("api", __name__, url_prefix="/api/")
MyModelApiView.add_rules_to_blueprint(blueprint)
# Available Endpoints:
# CREATE | curl -X POST "/api/v1/my-model" -H "Content-Type: application/json" \-d "{\"name\": \"Ayla\"}"
# LIST ALL | curl -X GET "/api/v1/my-model" -d "Accept: application/json"
# LIST ALL PAGINATED | curl -X GET "/api/v1/my-model?limit=100&offset=50" -d "Accept: application/json"
# SEARCH | curl -X GET "/api/v1/my-model?search=ayla" -d "Accept: application/json"
# FILTER | curl -X GET "/api/v1/my-model?filter={\"name\": \"Ayla\"}" -d "Accept: application/json"
# SORT | curl -X GET "/api/v1/my-model?sort=name" -d "Accept: application/json"
# FETCH | curl -X GET "/api/v1/my-model/1" -d "Accept: application/json"
# UPDATE | curl -X PUT "/api/v1/my-model" -H "Content-Type: application/json" \-d "{\"name\": \"Ayla\"}"
# PATCH | curl -X PATCH "/api/v1/my-model" -H "Content-Type: application/json" \-d "{\"name\": \"Ayla\"}"
# DELETE | curl -X DELETE "/api/v1/my-model/1"
Features
- Automatic generation of CRUD endpoints.
- Built-in search, filter, sort and pagination when listing resources.
- Support for APIs with nested resources (i.e. /api/classrooms/12345/students).
- Fully compatible with any other Flask method-based or class-based views. Mix & match with your existing views.
- Pre and post callbacks configurable on all manipulation endpoints. Allow for adding arbitrary logic before and after Create, Update or Delete operations.
Install
Flask-Muck is in Beta and does not have a standard version available for install yet. A standard release on PyPi is coming soon.
pip install flask-muck
Flask-Muck supports Python >= 3.9
Documentation
Refer to the examples directory for more information on usage and available features.
Full documentation is a work-in-progress but will be completed soon. It can be found here.
Issues
Submit any issues you may encounter on GitHub. Please search for similar issues before submitting a new one.
Support
Post any questions you have as a GitHub issue and add the "question" label.
License
MIT licensed. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_muck-0.0.3b5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ce2aaafaea794cad741620c716511198a452b53bf8b83a055e98abcf64309d1 |
|
MD5 | 58e6b5ede415993232fd831dd9e5a5ed |
|
BLAKE2b-256 | cf8da0b8f78ed17a04217598162aabdadbe275301aef24a131eba8f9f2d32866 |