flask-restx


Nameflask-restx JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/python-restx/flask-restx
SummaryFully featured framework for fast, easy and documented API development with Flask
upload_time2023-12-10 14:48:55
maintainer
docs_urlNone
authorpython-restx Authors
requires_python
licenseBSD-3-Clause
keywords flask restx rest api swagger openapi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===========
Flask RESTX
===========

.. image:: https://github.com/python-restx/flask-restx/workflows/Tests/badge.svg?tag=1.3.0&event=push
    :target: https://github.com/python-restx/flask-restx/actions?query=workflow%3ATests
    :alt: Tests status
.. image:: https://codecov.io/gh/python-restx/flask-restx/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/python-restx/flask-restx
    :alt: Code coverage
.. image:: https://readthedocs.org/projects/flask-restx/badge/?version=1.3.0
    :target: https://flask-restx.readthedocs.io/en/1.3.0/
    :alt: Documentation status
.. image:: https://img.shields.io/pypi/l/flask-restx.svg
    :target: https://pypi.org/project/flask-restx
    :alt: License
.. image:: https://img.shields.io/pypi/pyversions/flask-restx.svg
    :target: https://pypi.org/project/flask-restx
    :alt: Supported Python versions
.. image:: https://badges.gitter.im/Join%20Chat.svg
    :target: https://gitter.im/python-restx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
    :alt: Join the chat at https://gitter.im/python-restx
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
    :alt: Code style: black


Flask-RESTX is a community driven fork of `Flask-RESTPlus <https://github.com/noirbizarre/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 3.8+.

On Flask Compatibility
======================

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

.. list-table:: RESTX and Flask / Werkzeug Compatibility
    :widths: 25 25 25
    :header-rows: 1


    * - 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
      - < 3.0.0
      - unpinned, import statements wrapped for compatibility
    * - == 1.2.0
      - < 3.0.0
      - pinned in Flask-RESTX.
    * - >= 1.3.0
      - >= 2.0.0 (Flask >= 3.0.0 support)
      - unpinned, import statements wrapped for compatibility
    * - trunk branch in Github
      - >= 2.0.0 (Flask >= 3.0.0 support)
      - unpinned, will address issues faster than releases.

Installation
============

You can install Flask-RESTX with pip:

.. code-block:: console

    $ pip install flask-restx

or with easy_install:

.. code-block:: console

    $ easy_install flask-restx


Quick start
===========

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

.. code-block:: python

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


Documentation
=============

The documentation is hosted `on Read the Docs <http://flask-restx.readthedocs.io/en/latest/>`_


.. _Flask: https://flask.palletsprojects.com/
.. _Swagger: https://swagger.io/


Contribution
============
Want to contribute! That's awesome! Check out `CONTRIBUTING.rst! <https://github.com/python-restx/flask-restx/blob/master/CONTRIBUTING.rst>`_




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/python-restx/flask-restx",
    "name": "flask-restx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "flask restx rest api swagger openapi",
    "author": "python-restx Authors",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/45/4c/2e7d84e2b406b47cf3bf730f521efe474977b404ee170d8ea68dc37e6733/flask-restx-1.3.0.tar.gz",
    "platform": null,
    "description": "===========\nFlask RESTX\n===========\n\n.. image:: https://github.com/python-restx/flask-restx/workflows/Tests/badge.svg?tag=1.3.0&event=push\n    :target: https://github.com/python-restx/flask-restx/actions?query=workflow%3ATests\n    :alt: Tests status\n.. image:: https://codecov.io/gh/python-restx/flask-restx/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/python-restx/flask-restx\n    :alt: Code coverage\n.. image:: https://readthedocs.org/projects/flask-restx/badge/?version=1.3.0\n    :target: https://flask-restx.readthedocs.io/en/1.3.0/\n    :alt: Documentation status\n.. image:: https://img.shields.io/pypi/l/flask-restx.svg\n    :target: https://pypi.org/project/flask-restx\n    :alt: License\n.. image:: https://img.shields.io/pypi/pyversions/flask-restx.svg\n    :target: https://pypi.org/project/flask-restx\n    :alt: Supported Python versions\n.. image:: https://badges.gitter.im/Join%20Chat.svg\n    :target: https://gitter.im/python-restx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n    :alt: Join the chat at https://gitter.im/python-restx\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Code style: black\n\n\nFlask-RESTX is a community driven fork of `Flask-RESTPlus <https://github.com/noirbizarre/flask-restplus>`_.\n\n\nFlask-RESTX is an extension for `Flask`_ that adds support for quickly building REST APIs.\nFlask-RESTX encourages best practices with minimal setup.\nIf you are familiar with Flask, Flask-RESTX should be easy to pick up.\nIt provides a coherent collection of decorators and tools to describe your API\nand expose its documentation properly using `Swagger`_.\n\n\nCompatibility\n=============\n\nFlask-RESTX requires Python 3.8+.\n\nOn Flask Compatibility\n======================\n\nFlask and Werkzeug moved to versions 2.0 in March 2020. This caused a breaking change in Flask-RESTX.\n\n.. list-table:: RESTX and Flask / Werkzeug Compatibility\n    :widths: 25 25 25\n    :header-rows: 1\n\n\n    * - Flask-RESTX version\n      - Flask version\n      - Note\n    * - <= 0.3.0\n      - < 2.0.0\n      - unpinned in Flask-RESTX. Pin your projects!\n    * - == 0.4.0\n      - < 2.0.0\n      - pinned in Flask-RESTX.\n    * - >= 0.5.0\n      - < 3.0.0\n      - unpinned, import statements wrapped for compatibility\n    * - == 1.2.0\n      - < 3.0.0\n      - pinned in Flask-RESTX.\n    * - >= 1.3.0\n      - >= 2.0.0 (Flask >= 3.0.0 support)\n      - unpinned, import statements wrapped for compatibility\n    * - trunk branch in Github\n      - >= 2.0.0 (Flask >= 3.0.0 support)\n      - unpinned, will address issues faster than releases.\n\nInstallation\n============\n\nYou can install Flask-RESTX with pip:\n\n.. code-block:: console\n\n    $ pip install flask-restx\n\nor with easy_install:\n\n.. code-block:: console\n\n    $ easy_install flask-restx\n\n\nQuick start\n===========\n\nWith Flask-RESTX, you only import the api instance to route and document your endpoints.\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_restx import Api, Resource, fields\n\n    app = Flask(__name__)\n    api = Api(app, version='1.0', title='TodoMVC API',\n        description='A simple TodoMVC API',\n    )\n\n    ns = api.namespace('todos', description='TODO operations')\n\n    todo = api.model('Todo', {\n        'id': fields.Integer(readonly=True, description='The task unique identifier'),\n        'task': fields.String(required=True, description='The task details')\n    })\n\n\n    class TodoDAO(object):\n        def __init__(self):\n            self.counter = 0\n            self.todos = []\n\n        def get(self, id):\n            for todo in self.todos:\n                if todo['id'] == id:\n                    return todo\n            api.abort(404, \"Todo {} doesn't exist\".format(id))\n\n        def create(self, data):\n            todo = data\n            todo['id'] = self.counter = self.counter + 1\n            self.todos.append(todo)\n            return todo\n\n        def update(self, id, data):\n            todo = self.get(id)\n            todo.update(data)\n            return todo\n\n        def delete(self, id):\n            todo = self.get(id)\n            self.todos.remove(todo)\n\n\n    DAO = TodoDAO()\n    DAO.create({'task': 'Build an API'})\n    DAO.create({'task': '?????'})\n    DAO.create({'task': 'profit!'})\n\n\n    @ns.route('/')\n    class TodoList(Resource):\n        '''Shows a list of all todos, and lets you POST to add new tasks'''\n        @ns.doc('list_todos')\n        @ns.marshal_list_with(todo)\n        def get(self):\n            '''List all tasks'''\n            return DAO.todos\n\n        @ns.doc('create_todo')\n        @ns.expect(todo)\n        @ns.marshal_with(todo, code=201)\n        def post(self):\n            '''Create a new task'''\n            return DAO.create(api.payload), 201\n\n\n    @ns.route('/<int:id>')\n    @ns.response(404, 'Todo not found')\n    @ns.param('id', 'The task identifier')\n    class Todo(Resource):\n        '''Show a single todo item and lets you delete them'''\n        @ns.doc('get_todo')\n        @ns.marshal_with(todo)\n        def get(self, id):\n            '''Fetch a given resource'''\n            return DAO.get(id)\n\n        @ns.doc('delete_todo')\n        @ns.response(204, 'Todo deleted')\n        def delete(self, id):\n            '''Delete a task given its identifier'''\n            DAO.delete(id)\n            return '', 204\n\n        @ns.expect(todo)\n        @ns.marshal_with(todo)\n        def put(self, id):\n            '''Update a task given its identifier'''\n            return DAO.update(id, api.payload)\n\n\n    if __name__ == '__main__':\n        app.run(debug=True)\n\n\nContributors\n============\n\nFlask-RESTX is brought to you by @python-restx. Since early 2019 @SteadBytes,\n@a-luna, @j5awry, @ziirish volunteered to help @python-restx keep the project up\nand running, they did so for a long time! Since the beginning of 2023, the project\nis maintained by @peter-doggart with help from @ziirish.\nOf course everyone is welcome to contribute and we will be happy to review your\nPR's or answer to your issues.\n\n\nDocumentation\n=============\n\nThe documentation is hosted `on Read the Docs <http://flask-restx.readthedocs.io/en/latest/>`_\n\n\n.. _Flask: https://flask.palletsprojects.com/\n.. _Swagger: https://swagger.io/\n\n\nContribution\n============\nWant to contribute! That's awesome! Check out `CONTRIBUTING.rst! <https://github.com/python-restx/flask-restx/blob/master/CONTRIBUTING.rst>`_\n\n\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Fully featured framework for fast, easy and documented API development with Flask",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/python-restx/flask-restx"
    },
    "split_keywords": [
        "flask",
        "restx",
        "rest",
        "api",
        "swagger",
        "openapi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5bf1907369f2a7ee614dde5152ff8f811159d357e77962aa3f8c2e937f63731",
                "md5": "ea6a61b67c19b69616faddcfa57d3d17",
                "sha256": "636c56c3fb3f2c1df979e748019f084a938c4da2035a3e535a4673e4fc177691"
            },
            "downloads": -1,
            "filename": "flask_restx-1.3.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea6a61b67c19b69616faddcfa57d3d17",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 2798683,
            "upload_time": "2023-12-10T14:48:53",
            "upload_time_iso_8601": "2023-12-10T14:48:53.293004Z",
            "url": "https://files.pythonhosted.org/packages/a5/bf/1907369f2a7ee614dde5152ff8f811159d357e77962aa3f8c2e937f63731/flask_restx-1.3.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "454c2e7d84e2b406b47cf3bf730f521efe474977b404ee170d8ea68dc37e6733",
                "md5": "262984a0c902db0b6f4afb86a69ea40e",
                "sha256": "4f3d3fa7b6191fcc715b18c201a12cd875176f92ba4acc61626ccfd571ee1728"
            },
            "downloads": -1,
            "filename": "flask-restx-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "262984a0c902db0b6f4afb86a69ea40e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2814072,
            "upload_time": "2023-12-10T14:48:55",
            "upload_time_iso_8601": "2023-12-10T14:48:55.575815Z",
            "url": "https://files.pythonhosted.org/packages/45/4c/2e7d84e2b406b47cf3bf730f521efe474977b404ee170d8ea68dc37e6733/flask-restx-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-10 14:48:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "python-restx",
    "github_project": "flask-restx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-restx"
}
        
Elapsed time: 0.43623s