Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

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+.

On Flask Compatibility

Flask and Werkzeug moved to versions 2.0 in March 2020. This caused a breaking change in Flask-RESTX.

RESTX and Flask / Werkzeug Compatibility

Flask-RESTX version

Flask version

Note

<= 0.3.0

< 2.0.0

unpinned in Flask-RESTX. Pin your projects!

== 0.4.0

< 2.0.0

pinned in Flask-RESTX.

>= 0.5.0

All (For Now)

unpinned, import statements wrapped for compatibility

trunk branch in Github

All (and updated more often)

unpinned, will address issues faster than releases.

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!

Release files for flask-restx-jingapore 0.5.2.1.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-restx-jingapore 0.5.2.1.dev0
File Size Uploaded
flask-restx-jingapore-0.5.2.1.dev0.tar.gz 5.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-restx-jingapore 0.5.2.1.dev0
File Interpreter ABI Platform
flask_restx_jingapore-0.5.2.1.dev0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 10.6 MB

Release files / flask-restx-jingapore-0.5.2.1.dev0.tar.gz

Download URL flask-restx-jingapore-0.5.2.1.dev0.tar.gz
Size 5.3 MB
Tags Source
SHA-256 checksum
How to use checksums
093be9fbae77044763ed97c4326149e0e4eb369c8884336158b16fc4a6e838f9
BLAKE2b-256 checksum
How to use checksums
98ec772fed71db775ad911f13984755a540b49fe7589e95a09157f7d049127bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.2 requests/2.26.0 setuptools/59.4.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / flask_restx_jingapore-0.5.2.1.dev0-py2.py3-none-any.whl

Download URL flask_restx_jingapore-0.5.2.1.dev0-py2.py3-none-any.whl
Size 5.4 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
05402acc1fc1ca39327b41da557a3adabfef32d680ead86a2d056d250ba31e8d
BLAKE2b-256 checksum
How to use checksums
761e655d61b216f3953cac0cb1e4dd522db6015dbc313867ed1ba5dfa44b4c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.2 requests/2.26.0 setuptools/59.4.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.5.2.1.dev0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page