Building blocks for REST APIs for Flask
Project description
Building blocks for REST APIs for Flask.
Usage
Create a SQLAlchemy model and a marshmallow schema, then:
from flask_resty import Api, GenericModelView
from . import app, models, schemas
class WidgetViewBase(GenericModelView):
model = models.Widget
schema = models.WidgetSchema()
class WidgetListView(WidgetViewBase):
def get(self):
return self.list()
def post(self):
return self.create()
class WidgetView(WidgetViewBase):
def get(self, id):
return self.retrieve(id)
def patch(self, id):
return self.update(id, partial=True)
def delete(self, id):
return self.destroy(id)
api = Api(app, '/api')
api.add_resource('/widgets', WidgetListView, WidgetView)
By default, models are expected to have been created using Flask-SQLAlchemy.
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, String
from . import app
db = SQLAlchemy(app)
class Widget(db.Model):
id = Column(String, primary_key=True)
name = Column(String, nullable=False)
color = Column(String, nullable=False)
Schemas can be standard marshmallow Schema instances or marshmallow-sqlalchemy TableSchema instances. They should not be ModelSchema instances.
from marshmallow_sqlalchemy import TableSchema
from . import models
class WidgetSchema(TableSchema):
class Meta:
table = models.Widget.__table__
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
Flask-RESTy-0.20.6.tar.gz
(19.0 kB
view details)
Built Distribution
File details
Details for the file Flask-RESTy-0.20.6.tar.gz
.
File metadata
- Download URL: Flask-RESTy-0.20.6.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c7c599a103fd0499b78bc7fd9b77535a4b1415e10ecc0f1063e6895f96e4a5 |
|
MD5 | f2a02d902d26723bcd755cffc306011b |
|
BLAKE2b-256 | d3152ca1dd922dd063a550fad8267cf4c2da9d5b0adebd764c96823eadefa267 |
File details
Details for the file Flask_RESTy-0.20.6-py2.py3-none-any.whl
.
File metadata
- Download URL: Flask_RESTy-0.20.6-py2.py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2acdd85562777e768931c4a9092fad9c662dfcd765ff8e79dfbcfa7574746bef |
|
MD5 | 0a957d56bc66caff86b8aaa3d1a0e45b |
|
BLAKE2b-256 | 33eb809fac9505288a1d03ef350eae9394e70061517640b3f565e1852ed43fec |