Skip to main content

Batteries included framework for generating RESTful apis using Flask and SqlAlchemy.

Project description

Code style: black CI Testing CodeQL Docs Deploy types - Mypy Static Badge License - MIT downloads pypi version All Contributors

Flask-Muck

Logo

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 in as little as 9 lines of code.

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.

Documentation

Please visit the docs at https://dtiesling.github.io/flask-muck/ for explanation of all features and advanced usage guides.

There are also examples of complete Flask apps using Flask-Muck in the examples directory.

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

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.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

atkins
atkins

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_muck-0.1.1.tar.gz (783.6 kB view details)

Uploaded Source

Built Distribution

flask_muck-0.1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file flask_muck-0.1.1.tar.gz.

File metadata

  • Download URL: flask_muck-0.1.1.tar.gz
  • Upload date:
  • Size: 783.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for flask_muck-0.1.1.tar.gz
Algorithm Hash digest
SHA256 91331724f520b819ce15b3e067f1a7c99d73d4f46d50e3835676695c93d5de51
MD5 0f6bcd7f83150582e5cedad7d00436a6
BLAKE2b-256 6234e88cb08e4bcbc262e569426b6d51398f0aabf7178ac964c0336edb5d3389

See more details on using hashes here.

File details

Details for the file flask_muck-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flask_muck-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.25.2

File hashes

Hashes for flask_muck-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff5113b9a84aa16769077ce771b4a59023e2cb083156b4da710a5ec3c241e727
MD5 8a32de03f69d1ea3dc0cd08d0e322c8b
BLAKE2b-256 3e99db6913820e977d513a7afd63e03017ce4e988a11b5349433b5954b7fa447

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page