flask-apispec


Nameflask-apispec JSON
Version 0.6.0.post0 PyPI version JSON
download
home_pagehttps://github.com/jmcarp/flask-apispec
SummaryBuild and document REST APIs with Flask and apispec
upload_time2018-03-11 21:20:04
maintainer
docs_urlNone
authorJoshua Carp
requires_python
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 fields, Schema

    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 flask_apispec.extension import FlaskApiSpec

    app.config.update({
        'APISPEC_SPEC': APISpec(
            title='pets',
            version='v1',
            plugins=['apispec.ext.marshmallow'],
        ),
        '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

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "flask marshmallow webargs apispec", 
    "upload_time": "2018-03-11 21:20:04", 
    "author": "Joshua Carp", 
    "home_page": "https://github.com/jmcarp/flask-apispec", 
    "github_user": "jmcarp", 
    "download_url": "https://pypi.python.org/packages/ad/3a/b6317722f11c317b91d711644fe77e45c4b9758349c0e80257177ccbb777/flask-apispec-0.6.0.post0.tar.gz", 
    "platform": "", 
    "version": "0.6.0.post0", 
    "cheesecake_documentation_id": 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 fields, Schema\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 flask_apispec.extension import FlaskApiSpec\n\n    app.config.update({\n        'APISPEC_SPEC': APISpec(\n            title='pets',\n            version='v1',\n            plugins=['apispec.ext.marshmallow'],\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\n\n", 
    "tox": true, 
    "lcname": "flask-apispec", 
    "bugtrack_url": null, 
    "github": true, 
    "coveralls": false, 
    "name": "flask-apispec", 
    "license": "MIT", 
    "travis_ci": true, 
    "github_project": "flask-apispec", 
    "summary": "Build and document REST APIs with Flask and apispec", 
    "split_keywords": [
        "flask", 
        "marshmallow", 
        "webargs", 
        "apispec"
    ], 
    "author_email": "jm.carp@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-03-11T21:20:04", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/ad/3a/b6317722f11c317b91d711644fe77e45c4b9758349c0e80257177ccbb777/flask-apispec-0.6.0.post0.tar.gz", 
            "md5_digest": "ffa80d9b0e2f8df14fe9a4a022654fbd", 
            "downloads": 0, 
            "filename": "flask-apispec-0.6.0.post0.tar.gz", 
            "packagetype": "sdist", 
            "path": "ad/3a/b6317722f11c317b91d711644fe77e45c4b9758349c0e80257177ccbb777/flask-apispec-0.6.0.post0.tar.gz", 
            "size": 1009769
        }, 
        {
            "has_sig": false, 
            "upload_time": "2018-03-11T21:20:02", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/6b/67/46d5d92ce9701916f99cb740cb0ec7bc9b98b0dec03b829e19924e31eb8d/flask_apispec-0.6.0.post0-py2.py3-none-any.whl", 
            "md5_digest": "e84d7a66710f2cef3c1c974772fcd0c4", 
            "downloads": 0, 
            "filename": "flask_apispec-0.6.0.post0-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "6b/67/46d5d92ce9701916f99cb740cb0ec7bc9b98b0dec03b829e19924e31eb8d/flask_apispec-0.6.0.post0-py2.py3-none-any.whl", 
            "size": 1023246
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}