Package: jinjamator-flask-restx
Flask-RESTX is a community driven fork ofFlask-RESTPlus.Flask-RESTX is an extension forFlaskthat adds support for quickly building REST APIs.
Flask-RESTX encourages best practices with minimal setup.
If you are familiar with Flask, Flask-RESTX 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.CompatibilityFlask-RESTX requires Python 3.7+.On Flask CompatibilityFlask and Werkzeug moved to versions 2.0 in March 2020. This caused a breaking change in Flask-RESTX.RESTX and Flask / Werkzeug CompatibilityFlask-RESTX versionFlask versionNote<= 0.3.0< 2.0.0unpinned in Flask-RESTX. Pin your projects!== 0.4.0< 2.0.0pinned in Flask-RESTX.>= 0.5.0All (For Now)unpinned, import statements wrapped for compatibilitytrunk branch in GithubAll (and updated more often)unpinned, will address issues faster than releases.InstallationYou can install Flask-RESTX with pip:$pipinstallflask-restxor with easy_install:$easy_installflask-restxQuick startWith Flask-RESTX, you only import the api instance to route and document your endpoints.fromflaskimportFlaskfromflask_restximportApi,Resource,fieldsapp=Flask(__name__)api=Api(app,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)defget(self):'''List all tasks'''returnDAO.todos@ns.doc('create_todo')@ns.expect(todo)@ns.marshal_with(todo,code=201)defpost(self):'''Create a new task'''returnDAO.create(api.payload),201@ns.route('/<int:id>')@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)defget(self,id):'''Fetch a given resource'''returnDAO.get(id)@ns.doc('delete_todo')@ns.response(204,'Todo deleted')defdelete(self,id):'''Delete a task given its identifier'''DAO.delete(id)return'',204@ns.expect(todo)@ns.marshal_with(todo)defput(self,id):'''Update a task given its identifier'''returnDAO.update(id,api.payload)if__name__=='__main__':app.run(debug=True)ContributorsFlask-RESTX is brought to you by @python-restx. Since early 2019 @SteadBytes,
@a-luna, @j5awry, @ziirish volunteered to help @python-restx keep the project up
and running, they did so for a long time! Since the beginning of 2023, the project
is maintained by @peter-doggart with help from @ziirish.
Of course everyone is welcome to contribute and we will be happy to review your
PR’s or answer to your issues.DocumentationThe documentation is hostedon Read the DocsContributionWant to contribute! That’s awesome! Check outCONTRIBUTING.rst!