• Stars
    star
    2,730
  • Rank 16,103 (Top 0.4 %)
  • Language
    Python
  • License
    Other
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fully featured framework for fast, easy and documented API development with Flask

Flask RestPlus

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

IMPORTANT NOTICE:

This project has been forked to Flask-RESTX and will be maintained by by the python-restx organization. Flask-RESTPlus should be considered unmaintained.

The community has decided to fork the project due to lack of response from the original author @noirbizarre. We have been discussing this eventuality for almost a year.

Things evolved a bit since that discussion and a few of us have been granted maintainers access to the github project, but only the original author has access rights on the PyPi project. As such, we been unable to make any actual releases. To prevent this project from dying out, we have forked it to continue development and to support our users.

Flask-RESTPlus is an extension for Flask that adds support for quickly building REST APIs. Flask-RESTPlus encourages best practices with minimal setup. If you are familiar with Flask, Flask-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 using Swagger.

Compatibility

Flask-RestPlus requires Python 2.7 or 3.4+.

Installation

You can install Flask-Restplus with pip:

$ pip install flask-restplus

or with easy_install:

$ easy_install flask-restplus

Quick start

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

from flask import Flask
from flask_restplus 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-RESTPlus is brought to you by @noirbizarre. Since early 2019 @SteadBytes, @a-luna, @j5awry, @ziirish volunteered to help @noirbizarre 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!

More Repositories

1

django.js

Javascript tools for Django
JavaScript
180
star
2

gonja

Jinja-like syntax template-engine for Go
Go
100
star
3

django-eztables

Easy integration between jQuery DataTables and Django.
JavaScript
97
star
4

django-ember

Django Ember.js integration
JavaScript
58
star
5

django-absolute

Easy full absolute URLs for Django
Python
36
star
6

bumpr

Bump'R: Bump and release versions
Python
32
star
7

flask-fs

Simple and easy file storages for Flask
Python
31
star
8

pelican-microdata

Microdata semantic markups support for Pelican Blog Generator
Python
17
star
9

pdm-dockerize

Help generating docker images from PDM projects
Python
12
star
10

pytest-copier

A Copier plugin for pytest to help testing Copier templates
Python
8
star
11

pelican-frontmark

A Pelican CommonMark/Front Matter reader
Python
7
star
12

pelican-social

Social directives for Pelican static blog generator.
Python
6
star
13

airorm

An Active Record ORM for Flex/AIR
ActionScript
6
star
14

splashes

Elasticsearch loader and playground for SIRENE dataset
Python
5
star
15

minibench

A really simple benchmark tool
Python
4
star
16

ezwall-plugin

A Jenkins plugin that simply add a button to display a fullscreen buildwall on each view.
JavaScript
4
star
17

pelican-drafts

Add a browsable drafts listing to your Pelican website
Python
4
star
18

setuptools-meta

Easily store custom metadata with setuptools.
Python
3
star
19

umfactory

Factories for uMongo
Python
2
star
20

description-column

Jenkins Description Column Plugin
Java
1
star
21

gookie

A command-line utility to create projects (or parts of) using templates
1
star
22

git-doc

Illustrated git documentation
Python
1
star
23

config.nvim

My personal NeoViM configuration
Lua
1
star
24

strello

Extract some statistics from Trello JSON dump
Python
1
star
25

json4humans

Python tools for JSONC and JSON5 (aka. JSON for humans)
Python
1
star
26

slides-paris.py

Python Packaging Paris.py Meetup slides
JavaScript
1
star
27

pyss

Python CSS Compiler
1
star
28

virtualenvwrapper.tools

Some virtualenvwrapper extensions
Python
1
star
29

pelican-data

Data and collections management for Pelican
Python
1
star
30

need-checks

Expect or wait status checks for a commit
Python
1
star