flask-rebar


Nameflask-rebar JSON
Version 3.3.0 PyPI version JSON
download
home_pagehttps://github.com/plangrid/flask-rebar
SummaryFlask-Rebar combines flask, marshmallow, and swagger for robust REST services.
upload_time2024-04-15 21:25:58
maintainerNone
docs_urlNone
authorBarak Alon
requires_pythonNone
licenseMIT
keywords flask rest marshmallow openapi swagger
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Flask-Rebar
===========

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

.. image:: https://github.com/plangrid/flask-rebar/actions/workflows/tag.yml/badge.svg
   :target: https://github.com/plangrid/flask-rebar/actions/workflows/tag.yml
   :alt: CI Status

.. image:: https://badge.fury.io/py/flask-rebar.svg
   :target: https://badge.fury.io/py/flask-rebar
   :alt: PyPI status

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
   :target: https://github.com/ambv/black
   :alt: Code style

.. image:: https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg
   :target: https://www.contributor-covenant.org/
   :alt: Code of Conduct

|

Flask-Rebar combines `flask <http://flask.pocoo.org/>`_, `marshmallow <https://marshmallow.readthedocs.io/en/latest/>`_, and `swagger <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`_ for robust REST services.


Features
--------

* **Request and Response Validation** - Flask-Rebar relies on schemas from the popular Marshmallow package to validate incoming requests and marshal outgoing responses.
* **Automatic Swagger Generation** - The same schemas used for validation and marshaling are used to automatically generate OpenAPI specifications (a.k.a. Swagger). This also means automatic documentation via `Swagger UI <https://swagger.io/swagger-ui/>`_.
* **Error Handling** - Uncaught exceptions from Flask-Rebar are converted to appropriate HTTP errors.


Example
-------

.. code-block:: python

   from flask import Flask
   from flask_rebar import errors, Rebar
   from marshmallow import fields, Schema

   from my_app import database


   rebar = Rebar()

   # All handler URL rules will be prefixed by '/v1'
   registry = rebar.create_handler_registry(prefix='/v1')

   class TodoSchema(Schema):
       id = fields.Integer()
       complete = fields.Boolean()
       description = fields.String()

   # This schema will validate the incoming request's query string
   class GetTodosQueryStringSchema(Schema):
       complete = fields.Boolean()

   # This schema will marshal the outgoing response
   class GetTodosResponseSchema(Schema):
       data = fields.Nested(TodoSchema, many=True)


   @registry.handles(
       rule='/todos',
       method='GET',
       query_string_schema=GetTodosQueryStringSchema(),
       response_body_schema=GetTodosResponseSchema(), # for versions <= 1.7.0, use marshal_schema
   )
   def get_todos():
       """
       This docstring will be rendered as the operation's description in
       the auto-generated OpenAPI specification.
       """
       # The query string has already been validated by `query_string_schema`
       complete = rebar.validated_args.get('complete')

       ...

       # Errors are converted to appropriate HTTP errors
       raise errors.Forbidden()

       ...

       # The response will be marshaled by `marshal_schema`
       return {'data': []}


   def create_app(name):
       app = Flask(name)
       rebar.init_app(app)
       return app


   if __name__ == '__main__':
       create_app(__name__).run()


For a more complete example, check out the example app at `examples/todo.py <examples/todo/todo.py>`_. Some example requests to this example app can be found at `examples/todo_output.md <examples/todo/todo_output.md>`_.


Installation
------------

.. code-block::

   pip install flask-rebar


Replacing static swagger-ui files
---------------------------------

If you'd like to replace swagger-ui's static files (`flask_rebar/swagger_ui/static`) with those of the latest release,
run the following from the root of the project.

.. code-block::
    
    curl -L https://api.github.com/repos/swagger-api/swagger-ui/tarball | tar -xv --directory=flask_rebar/swagger_ui/static --strip-components=2 "*/dist/"

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

More extensive documentation can be found  `here <https://flask-rebar.readthedocs.io>`_.


Extensions
----------

Flask-Rebar is extensible! Here are some open source extensions:

* `Flask-Rebar-Auth0 <https://github.com/Sytten/flask-rebar-auth0>`_ - `Auth0 <https://auth0.com/>`_ authenticator for Flask-Rebar


Contributing
------------

There is still work to be done, and contributions are encouraged! Check out the `contribution guide <CONTRIBUTING.rst>`_ for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/plangrid/flask-rebar",
    "name": "flask-rebar",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "flask, rest, marshmallow, openapi, swagger",
    "author": "Barak Alon",
    "author_email": "barak.s.alon@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8b/af/14b9b0ec64b8688ae38be5e825ed7e7fdaad2e174f1f52a8aa61bb6fc1e9/flask_rebar-3.3.0.tar.gz",
    "platform": null,
    "description": "Flask-Rebar\n===========\n\n.. image:: https://readthedocs.org/projects/flask-rebar/badge/?version=latest\n   :target: http://flask-rebar.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\n.. image:: https://github.com/plangrid/flask-rebar/actions/workflows/tag.yml/badge.svg\n   :target: https://github.com/plangrid/flask-rebar/actions/workflows/tag.yml\n   :alt: CI Status\n\n.. image:: https://badge.fury.io/py/flask-rebar.svg\n   :target: https://badge.fury.io/py/flask-rebar\n   :alt: PyPI status\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/ambv/black\n   :alt: Code style\n\n.. image:: https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg\n   :target: https://www.contributor-covenant.org/\n   :alt: Code of Conduct\n\n|\n\nFlask-Rebar combines `flask <http://flask.pocoo.org/>`_, `marshmallow <https://marshmallow.readthedocs.io/en/latest/>`_, and `swagger <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md>`_ for robust REST services.\n\n\nFeatures\n--------\n\n* **Request and Response Validation** - Flask-Rebar relies on schemas from the popular Marshmallow package to validate incoming requests and marshal outgoing responses.\n* **Automatic Swagger Generation** - The same schemas used for validation and marshaling are used to automatically generate OpenAPI specifications (a.k.a. Swagger). This also means automatic documentation via `Swagger UI <https://swagger.io/swagger-ui/>`_.\n* **Error Handling** - Uncaught exceptions from Flask-Rebar are converted to appropriate HTTP errors.\n\n\nExample\n-------\n\n.. code-block:: python\n\n   from flask import Flask\n   from flask_rebar import errors, Rebar\n   from marshmallow import fields, Schema\n\n   from my_app import database\n\n\n   rebar = Rebar()\n\n   # All handler URL rules will be prefixed by '/v1'\n   registry = rebar.create_handler_registry(prefix='/v1')\n\n   class TodoSchema(Schema):\n       id = fields.Integer()\n       complete = fields.Boolean()\n       description = fields.String()\n\n   # This schema will validate the incoming request's query string\n   class GetTodosQueryStringSchema(Schema):\n       complete = fields.Boolean()\n\n   # This schema will marshal the outgoing response\n   class GetTodosResponseSchema(Schema):\n       data = fields.Nested(TodoSchema, many=True)\n\n\n   @registry.handles(\n       rule='/todos',\n       method='GET',\n       query_string_schema=GetTodosQueryStringSchema(),\n       response_body_schema=GetTodosResponseSchema(), # for versions <= 1.7.0, use marshal_schema\n   )\n   def get_todos():\n       \"\"\"\n       This docstring will be rendered as the operation's description in\n       the auto-generated OpenAPI specification.\n       \"\"\"\n       # The query string has already been validated by `query_string_schema`\n       complete = rebar.validated_args.get('complete')\n\n       ...\n\n       # Errors are converted to appropriate HTTP errors\n       raise errors.Forbidden()\n\n       ...\n\n       # The response will be marshaled by `marshal_schema`\n       return {'data': []}\n\n\n   def create_app(name):\n       app = Flask(name)\n       rebar.init_app(app)\n       return app\n\n\n   if __name__ == '__main__':\n       create_app(__name__).run()\n\n\nFor a more complete example, check out the example app at `examples/todo.py <examples/todo/todo.py>`_. Some example requests to this example app can be found at `examples/todo_output.md <examples/todo/todo_output.md>`_.\n\n\nInstallation\n------------\n\n.. code-block::\n\n   pip install flask-rebar\n\n\nReplacing static swagger-ui files\n---------------------------------\n\nIf you'd like to replace swagger-ui's static files (`flask_rebar/swagger_ui/static`) with those of the latest release,\nrun the following from the root of the project.\n\n.. code-block::\n    \n    curl -L https://api.github.com/repos/swagger-api/swagger-ui/tarball | tar -xv --directory=flask_rebar/swagger_ui/static --strip-components=2 \"*/dist/\"\n\nDocumentation\n-------------\n\nMore extensive documentation can be found  `here <https://flask-rebar.readthedocs.io>`_.\n\n\nExtensions\n----------\n\nFlask-Rebar is extensible! Here are some open source extensions:\n\n* `Flask-Rebar-Auth0 <https://github.com/Sytten/flask-rebar-auth0>`_ - `Auth0 <https://auth0.com/>`_ authenticator for Flask-Rebar\n\n\nContributing\n------------\n\nThere is still work to be done, and contributions are encouraged! Check out the `contribution guide <CONTRIBUTING.rst>`_ for more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Flask-Rebar combines flask, marshmallow, and swagger for robust REST services.",
    "version": "3.3.0",
    "project_urls": {
        "Homepage": "https://github.com/plangrid/flask-rebar"
    },
    "split_keywords": [
        "flask",
        " rest",
        " marshmallow",
        " openapi",
        " swagger"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ca0ad2f08fce67eb56b5018f88937a3ec3be6f6d4404220c9c5165bde69fa816",
                "md5": "387b4f66337a17ea862436d537b3e94e",
                "sha256": "027a91f33133965e3961238934872c89f5ed28a8f99c0c5f2384b623ce872739"
            },
            "downloads": -1,
            "filename": "flask_rebar-3.3.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "387b4f66337a17ea862436d537b3e94e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 3212238,
            "upload_time": "2024-04-15T21:25:56",
            "upload_time_iso_8601": "2024-04-15T21:25:56.072307Z",
            "url": "https://files.pythonhosted.org/packages/ca/0a/d2f08fce67eb56b5018f88937a3ec3be6f6d4404220c9c5165bde69fa816/flask_rebar-3.3.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8baf14b9b0ec64b8688ae38be5e825ed7e7fdaad2e174f1f52a8aa61bb6fc1e9",
                "md5": "da2e522984c4d992fc3c445d462a7694",
                "sha256": "d93f9cca83ddd31e3379e4bde741dfb704fd56b8964a81108f20ba023de565b0"
            },
            "downloads": -1,
            "filename": "flask_rebar-3.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "da2e522984c4d992fc3c445d462a7694",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3178293,
            "upload_time": "2024-04-15T21:25:58",
            "upload_time_iso_8601": "2024-04-15T21:25:58.695989Z",
            "url": "https://files.pythonhosted.org/packages/8b/af/14b9b0ec64b8688ae38be5e825ed7e7fdaad2e174f1f52a8aa61bb6fc1e9/flask_rebar-3.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-15 21:25:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "plangrid",
    "github_project": "flask-rebar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flask-rebar"
}
        
Elapsed time: 0.29232s