flask-apispec-hyper


Nameflask-apispec-hyper JSON
Version 0.12.0 PyPI version JSON
download
home_pagehttps://github.com/hyperflask/flask-apispec-hyper
SummaryBuild and document REST APIs with Flask and apispec
upload_time2024-09-02 22:00:39
maintainerNone
docs_urlNone
authorJoshua Carp
requires_python>=3.8
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/hyperflask/flask-apispec-hyper",
    "name": "flask-apispec-hyper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flask marshmallow webargs apispec",
    "author": "Joshua Carp",
    "author_email": "jm.carp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/44/ce75b9dbdc31fe4bbfa734391b998169ce7950bf596a9a3a1556ef318069/flask_apispec_hyper-0.12.0.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.12.0",
    "project_urls": {
        "Bug Reports": "https://github.com/hyperflask/flask-apispec-hyper/issues",
        "Changelog": "https://flask-apispec.readthedocs.io/en/latest/changelog.html",
        "Homepage": "https://github.com/hyperflask/flask-apispec-hyper"
    },
    "split_keywords": [
        "flask",
        "marshmallow",
        "webargs",
        "apispec"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4944ce75b9dbdc31fe4bbfa734391b998169ce7950bf596a9a3a1556ef318069",
                "md5": "624cdc6d9e1a638035ec385733e771df",
                "sha256": "50531b3a42061fce531ef1f5ac94a7356cd72141280d5197e2a2dfd0e805a7b5"
            },
            "downloads": -1,
            "filename": "flask_apispec_hyper-0.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "624cdc6d9e1a638035ec385733e771df",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 30146,
            "upload_time": "2024-09-02T22:00:39",
            "upload_time_iso_8601": "2024-09-02T22:00:39.321442Z",
            "url": "https://files.pythonhosted.org/packages/49/44/ce75b9dbdc31fe4bbfa734391b998169ce7950bf596a9a3a1556ef318069/flask_apispec_hyper-0.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-02 22:00:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hyperflask",
    "github_project": "flask-apispec-hyper",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "flask-apispec-hyper"
}
        
Elapsed time: 1.63525s