Package: sanic-restplus
Sanic-RESTPlus is an extension forSanicthat adds support for quickly building REST APIs.
Sanic-RESTPlus encourages best practices with minimal setup.
If you are familiar with Sanic, Sanic-RESTPlus should be easy to pick up.
It provides a coherent collection of decorators and tools to describe your API
and expose its documentation properly usingSwagger.CompatibilitySanic-RestPlus requires Python 3.7+.Sanic-RestPlus works with Sanic v21.3+Sanic-RestPlus IS NOT CURRENTLY COMPATIBLE with Sanic v21.12 or above (due to limitations in sanic-plugin-toolkit).Backward Compatibility NoticeSanic-RestPlus version 0.6.0 was reworked and now requires Sanic v21.3 or later.Sanic-RestPlus version 0.4.1 (and previous versions)does not workon Sanic 19.12+, see this bug here:https://github.com/ashleysommer/sanicpluginsframework/issues/15Please use Sanic-Restplus v0.5.x if you need to deploy on Sanic v19.12 or v20.12If you are using the Sanic v20.12LTS, please use Sanic-RestPlus v0.5.6.InstallationIn the near future, you will be able to install Sanic-Restplus with pip:$pipinstallsanic-restplusor with easy_install:$easy_installsanic-restplusQuick startWith Sanic-Restplus, you only import the api instance to route and document your endpoints.fromsanicimportSanicfromsanic_restplusimportApi,Resource,fieldsfromsanic_restplus.restplusimportrestplusfromsanic_plugin_toolkitimportSanicPluginRealmapp=Sanic(__name__)realm=SanicPluginRealm(app)rest_assoc=realm.register_plugin(restplus)api=Api(version='1.0',title='TodoMVC API',description='A simple TodoMVC API')ns=api.namespace('todos',description='TODO operations')todo=api.model('Todo',{'id':fields.Integer(readOnly=True,description='The task unique identifier'),'task':fields.String(required=True,description='The task details')})classTodoDAO(object):def__init__(self):self.counter=0self.todos=[]defget(self,id):fortodoinself.todos:iftodo['id']==id:returntodoapi.abort(404,"Todo{}doesn't exist".format(id))defcreate(self,data):todo=datatodo['id']=self.counter=self.counter+1self.todos.append(todo)returntododefupdate(self,id,data):todo=self.get(id)todo.update(data)returntododefdelete(self,id):todo=self.get(id)self.todos.remove(todo)DAO=TodoDAO()DAO.create({'task':'Build an API'})DAO.create({'task':'?????'})DAO.create({'task':'profit!'})@ns.route('/')classTodoList(Resource):'''Shows a list of all todos, and lets you POST to add new tasks'''@ns.doc('list_todos')@ns.marshal_list_with(todo)asyncdefget(self,request):'''List all tasks'''returnDAO.todos@ns.doc('create_todo')@ns.expect(todo)@ns.marshal_with(todo,code=201)asyncdefpost(self,request):'''Create a new task'''returnDAO.create(request.json),201@ns.route('/<id:int>')@ns.response(404,'Todo not found')@ns.param('id','The task identifier')classTodo(Resource):'''Show a single todo item and lets you delete them'''@ns.doc('get_todo')@ns.marshal_with(todo)asyncdefget(self,request,id):'''Fetch a given resource'''returnDAO.get(id)@ns.doc('delete_todo')@ns.response(204,'Todo deleted')asyncdefdelete(self,request,id):'''Delete a task given its identifier'''DAO.delete(id)return'',204@ns.expect(todo)@ns.marshal_with(todo)asyncdefput(self,request,id):'''Update a task given its identifier'''returnDAO.update(id,request.json)rest_assoc.api(api)if__name__=='__main__':app.run(debug=True,auto_reload=False)DocumentationThe documentation is hostedon Read the DocsThat is the Flask RestPlus documentation, the Sanic-Restplus docs are not converted yet.REMOVED Flask-Restplus changelog. See the flask-restplus changelog in the relevant parent repository.