Skip to content
Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
Python Other
  1. Python 98.8%
  2. Other 1.2%
Branch: master
Clone or download
ziirish and SteadBytes allow travis to push releases on PyPi
This change allows Travis-CI to build and publish new releases on
PyPi.org upon tag additions.
The bumpr.rc file has been changed accordingly since we won't use it
anymore to push new releases directly, but we may still use it to
prepare new releases (ie. edit the CHANGELOG, README, etc.)
Latest commit c9f90a4 Jan 15, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github restplus-> restx find & replace Jan 12, 2020
doc Rename config variables: RESTPLUS_* -> RESTX_* Jan 13, 2020
examples restplus-> restx find & replace Jan 12, 2020
flask_restx allow travis to push releases on PyPi Jan 18, 2020
requirements fix: PyPi description parsing Jan 12, 2020
tests Rename config variables: RESTPLUS_* -> RESTX_* Jan 13, 2020
.editorconfig Added editorconfig Jan 15, 2017
.gitignore restplus-> restx find & replace Jan 12, 2020
.pyup.yml Added pyup config Oct 24, 2017
.travis.yml allow travis to push releases on PyPi Jan 18, 2020
CONTRIBUTING.rst allow travis to push releases on PyPi Jan 18, 2020
LICENSE Update project authors Jan 12, 2020
MANIFEST.in Remove CHANGELOG.rst Jan 12, 2020
README.rst restplus-> restx find & replace Jan 12, 2020
bumpr.rc allow travis to push releases on PyPi Jan 18, 2020
coverage.rc restplus-> restx find & replace Jan 12, 2020
package.json restplus-> restx find & replace Jan 12, 2020
readthedocs.pip
setup.cfg Remove pytest warning about custom markers Aug 13, 2019
setup.py Update project authors Jan 12, 2020
tasks.py fix: PyPi description parsing Jan 12, 2020
tox.ini Fix tox dependencies installation Aug 13, 2019
travis-bench-after-success.sh

README.rst

Flask RESTX

Build status Code coverage Documentation status License Supported Python versions Join the chat at https://gitter.im/python-restx

Flask-RESTX is a community driven fork of Flask-RESTPlus.

Flask-RESTX is an extension for Flask that 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 using Swagger.

Compatibility

Flask-RESTX requires Python 2.7 or 3.4+.

Installation

You can install Flask-RESTX with pip:

$ pip install flask-restx

or with easy_install:

$ easy_install flask-restx

Quick start

With Flask-RESTX, you only import the api instance to route and document your endpoints.

from flask import Flask
from flask_restx import Api, Resource, fields

app = 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')
})


class TodoDAO(object):
    def __init__(self):
        self.counter = 0
        self.todos = []

    def get(self, id):
        for todo in self.todos:
            if todo['id'] == id:
                return todo
        api.abort(404, "Todo {} doesn't exist".format(id))

    def create(self, data):
        todo = data
        todo['id'] = self.counter = self.counter + 1
        self.todos.append(todo)
        return todo

    def update(self, id, data):
        todo = self.get(id)
        todo.update(data)
        return todo

    def delete(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('/')
class TodoList(Resource):
    '''Shows a list of all todos, and lets you POST to add new tasks'''
    @ns.doc('list_todos')
    @ns.marshal_list_with(todo)
    def get(self):
        '''List all tasks'''
        return DAO.todos

    @ns.doc('create_todo')
    @ns.expect(todo)
    @ns.marshal_with(todo, code=201)
    def post(self):
        '''Create a new task'''
        return DAO.create(api.payload), 201


@ns.route('/<int:id>')
@ns.response(404, 'Todo not found')
@ns.param('id', 'The task identifier')
class Todo(Resource):
    '''Show a single todo item and lets you delete them'''
    @ns.doc('get_todo')
    @ns.marshal_with(todo)
    def get(self, id):
        '''Fetch a given resource'''
        return DAO.get(id)

    @ns.doc('delete_todo')
    @ns.response(204, 'Todo deleted')
    def delete(self, id):
        '''Delete a task given its identifier'''
        DAO.delete(id)
        return '', 204

    @ns.expect(todo)
    @ns.marshal_with(todo)
    def put(self, id):
        '''Update a task given its identifier'''
        return DAO.update(id, api.payload)


if __name__ == '__main__':
    app.run(debug=True)

Contributors

Flask-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. Of course everyone is welcome to contribute and we will be happy to review your PR's or answer to your issues.

Documentation

The documentation is hosted on Read the Docs

Contribution

Want to contribute! That's awesome! Check out CONTRIBUTING.rst!

You can’t perform that action at this time.