flask-apispec


Nameflask-apispec JSON
Version 0.11.4 PyPI version JSON
download
home_pagehttps://github.com/jmcarp/flask-apispec
SummaryBuild and document REST APIs with Flask and apispec
upload_time2022-08-11 23:31:48
maintainer
docs_urlNone
authorJoshua Carp
requires_python>=3.6
licenseMIT
keywords flask marshmallow webargs apispec
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            =============
flask-apispec
=============

.. image:: https://img.shields.io/pypi/v/flask-apispec.svg
    :target: http://badge.fury.io/py/flask-apispec
    :alt: Latest version

.. image:: https://readthedocs.org/projects/flask-apispec/badge/?version=latest
    :target: https://flask-apispec.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation status

.. image:: https://img.shields.io/travis/jmcarp/flask-apispec/master.svg
    :target: https://travis-ci.org/jmcarp/flask-apispec
    :alt: Travis-CI

.. image:: https://img.shields.io/codecov/c/github/jmcarp/flask-apispec/master.svg
    :target: https://codecov.io/github/jmcarp/flask-apispec
    :alt: Code coverage

**flask-apispec** is a lightweight tool for building REST APIs in Flask. **flask-apispec** uses webargs_ for request parsing, marshmallow_ for response formatting, and apispec_ to automatically generate Swagger markup. You can use **flask-apispec** with vanilla Flask or a fuller-featured framework like Flask-RESTful_.

Install
-------

::

    pip install flask-apispec

Quickstart
----------

.. code-block:: python

    from flask import Flask
    from flask_apispec import use_kwargs, marshal_with

    from marshmallow import Schema
    from webargs import fields

    from .models import Pet

    app = Flask(__name__)

    class PetSchema(Schema):
        class Meta:
            fields = ('name', 'category', 'size')

    @app.route('/pets')
    @use_kwargs({'category': fields.Str(), 'size': fields.Str()})
    @marshal_with(PetSchema(many=True))
    def get_pets(**kwargs):
        return Pet.query.filter_by(**kwargs)

**flask-apispec** works with function- and class-based views:

.. code-block:: python

    from flask import make_response
    from flask_apispec.views import MethodResource

    class PetResource(MethodResource):

        @marshal_with(PetSchema)
        def get(self, pet_id):
            return Pet.query.filter(Pet.id == pet_id).one()

        @use_kwargs(PetSchema)
        @marshal_with(PetSchema, code=201)
        def post(self, **kwargs):
            return Pet(**kwargs)

        @use_kwargs(PetSchema)
        @marshal_with(PetSchema)
        def put(self, pet_id, **kwargs):
            pet = Pet.query.filter(Pet.id == pet_id).one()
            pet.__dict__.update(**kwargs)
            return pet

        @marshal_with(None, code=204)
        def delete(self, pet_id):
            pet = Pet.query.filter(Pet.id == pet_id).one()
            pet.delete()
            return make_response('', 204)

**flask-apispec** generates Swagger markup for your view functions and classes. By default, Swagger JSON is served at `/swagger/`, and Swagger-UI at `/swagger-ui/`.

.. code-block:: python

    from apispec import APISpec
    from apispec.ext.marshmallow import MarshmallowPlugin
    from flask_apispec.extension import FlaskApiSpec

    app.config.update({
        'APISPEC_SPEC': APISpec(
            title='pets',
            version='v1',
            plugins=[MarshmallowPlugin()],
        ),
        'APISPEC_SWAGGER_URL': '/swagger/',
    })
    docs = FlaskApiSpec(app)

    docs.register(get_pets)
    docs.register(PetResource)

Documentation
-------------

https://flask-apispec.readthedocs.io/

Notes
-----

**flask-apispec** is strongly inspired by Flask-RESTful_ and Flask-RESTplus_, but attempts to provide similar functionality with greater flexibility and less code.

.. _webargs: https://webargs.readthedocs.io/
.. _marshmallow: https://marshmallow.readthedocs.io/
.. _apispec: https://apispec.readthedocs.io/
.. _Flask-RESTful: https://flask-restful.readthedocs.io/
.. _Flask-RESTplus: https://flask-restplus.readthedocs.io/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jmcarp/flask-apispec",
    "name": "flask-apispec",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "flask marshmallow webargs apispec",
    "author": "Joshua Carp",
    "author_email": "jm.carp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ac/a1/90402387bbe235f3206c0aa0bd1815fce042ac2370b1d3c8ceaa16149074/flask-apispec-0.11.4.tar.gz",
    "platform": null,
    "description": "=============\nflask-apispec\n=============\n\n.. image:: https://img.shields.io/pypi/v/flask-apispec.svg\n    :target: http://badge.fury.io/py/flask-apispec\n    :alt: Latest version\n\n.. image:: https://readthedocs.org/projects/flask-apispec/badge/?version=latest\n    :target: https://flask-apispec.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation status\n\n.. image:: https://img.shields.io/travis/jmcarp/flask-apispec/master.svg\n    :target: https://travis-ci.org/jmcarp/flask-apispec\n    :alt: Travis-CI\n\n.. image:: https://img.shields.io/codecov/c/github/jmcarp/flask-apispec/master.svg\n    :target: https://codecov.io/github/jmcarp/flask-apispec\n    :alt: Code coverage\n\n**flask-apispec** is a lightweight tool for building REST APIs in Flask. **flask-apispec** uses webargs_ for request parsing, marshmallow_ for response formatting, and apispec_ to automatically generate Swagger markup. You can use **flask-apispec** with vanilla Flask or a fuller-featured framework like Flask-RESTful_.\n\nInstall\n-------\n\n::\n\n    pip install flask-apispec\n\nQuickstart\n----------\n\n.. code-block:: python\n\n    from flask import Flask\n    from flask_apispec import use_kwargs, marshal_with\n\n    from marshmallow import Schema\n    from webargs import fields\n\n    from .models import Pet\n\n    app = Flask(__name__)\n\n    class PetSchema(Schema):\n        class Meta:\n            fields = ('name', 'category', 'size')\n\n    @app.route('/pets')\n    @use_kwargs({'category': fields.Str(), 'size': fields.Str()})\n    @marshal_with(PetSchema(many=True))\n    def get_pets(**kwargs):\n        return Pet.query.filter_by(**kwargs)\n\n**flask-apispec** works with function- and class-based views:\n\n.. code-block:: python\n\n    from flask import make_response\n    from flask_apispec.views import MethodResource\n\n    class PetResource(MethodResource):\n\n        @marshal_with(PetSchema)\n        def get(self, pet_id):\n            return Pet.query.filter(Pet.id == pet_id).one()\n\n        @use_kwargs(PetSchema)\n        @marshal_with(PetSchema, code=201)\n        def post(self, **kwargs):\n            return Pet(**kwargs)\n\n        @use_kwargs(PetSchema)\n        @marshal_with(PetSchema)\n        def put(self, pet_id, **kwargs):\n            pet = Pet.query.filter(Pet.id == pet_id).one()\n            pet.__dict__.update(**kwargs)\n            return pet\n\n        @marshal_with(None, code=204)\n        def delete(self, pet_id):\n            pet = Pet.query.filter(Pet.id == pet_id).one()\n            pet.delete()\n            return make_response('', 204)\n\n**flask-apispec** generates Swagger markup for your view functions and classes. By default, Swagger JSON is served at `/swagger/`, and Swagger-UI at `/swagger-ui/`.\n\n.. code-block:: python\n\n    from apispec import APISpec\n    from apispec.ext.marshmallow import MarshmallowPlugin\n    from flask_apispec.extension import FlaskApiSpec\n\n    app.config.update({\n        'APISPEC_SPEC': APISpec(\n            title='pets',\n            version='v1',\n            plugins=[MarshmallowPlugin()],\n        ),\n        'APISPEC_SWAGGER_URL': '/swagger/',\n    })\n    docs = FlaskApiSpec(app)\n\n    docs.register(get_pets)\n    docs.register(PetResource)\n\nDocumentation\n-------------\n\nhttps://flask-apispec.readthedocs.io/\n\nNotes\n-----\n\n**flask-apispec** is strongly inspired by Flask-RESTful_ and Flask-RESTplus_, but attempts to provide similar functionality with greater flexibility and less code.\n\n.. _webargs: https://webargs.readthedocs.io/\n.. _marshmallow: https://marshmallow.readthedocs.io/\n.. _apispec: https://apispec.readthedocs.io/\n.. _Flask-RESTful: https://flask-restful.readthedocs.io/\n.. _Flask-RESTplus: https://flask-restplus.readthedocs.io/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Build and document REST APIs with Flask and apispec",
    "version": "0.11.4",
    "project_urls": {
        "Bug Reports": "https://github.com/jmcarp/flask-apispec/issues",
        "Changelog": "https://flask-apispec.readthedocs.io/en/latest/changelog.html",
        "Homepage": "https://github.com/jmcarp/flask-apispec"
    },
    "split_keywords": [
        "flask",
        "marshmallow",
        "webargs",
        "apispec"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5060b443700936d93236ad571e6afea21a8de81ed73fbfd26e74ee1a62fd9ec",
                "md5": "b05392bbe4235271fadd26097b3e1706",
                "sha256": "dba490a42ffe5e45040a667a5551678099c677eb65b6d5e420cf59ce1dcb6adb"
            },
            "downloads": -1,
            "filename": "flask_apispec-0.11.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b05392bbe4235271fadd26097b3e1706",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.6",
            "size": 2358749,
            "upload_time": "2022-08-11T23:31:45",
            "upload_time_iso_8601": "2022-08-11T23:31:45.094790Z",
            "url": "https://files.pythonhosted.org/packages/e5/06/0b443700936d93236ad571e6afea21a8de81ed73fbfd26e74ee1a62fd9ec/flask_apispec-0.11.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aca190402387bbe235f3206c0aa0bd1815fce042ac2370b1d3c8ceaa16149074",
                "md5": "2610e9975849bc815762458316ee6b32",
                "sha256": "9a6fedd3a06510a8a19340df676393b336b4ba9d5c159cbb304b62672e3115da"
            },
            "downloads": -1,
            "filename": "flask-apispec-0.11.4.tar.gz",
            "has_sig": false,
            "md5_digest": "2610e9975849bc815762458316ee6b32",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 2335497,
            "upload_time": "2022-08-11T23:31:48",
            "upload_time_iso_8601": "2022-08-11T23:31:48.491937Z",
            "url": "https://files.pythonhosted.org/packages/ac/a1/90402387bbe235f3206c0aa0bd1815fce042ac2370b1d3c8ceaa16149074/flask-apispec-0.11.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-11 23:31:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jmcarp",
    "github_project": "flask-apispec",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "flask-apispec"
}
        
Elapsed time: 0.40425s