flask-rebar


Nameflask-rebar JSON
Version 3.3.2 PyPI version JSON
download
home_pagehttps://github.com/plangrid/flask-rebar
SummaryFlask-Rebar combines flask, marshmallow, and swagger for robust REST services.
upload_time2024-10-10 17:58:56
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/fb/6b/0ed6e48d50db99f82b4d03c5e41c19837c074edd9ce08794e1e1aa46266d/flask_rebar-3.3.2.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.2",
    "project_urls": {
        "Homepage": "https://github.com/plangrid/flask-rebar"
    },
    "split_keywords": [
        "flask",
        " rest",
        " marshmallow",
        " openapi",
        " swagger"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "20d0ce3623f6026969887ef66acb59612678d55493560258269327b40d430570",
                "md5": "a22944adce8fd1643fe64ae25b6f4eca",
                "sha256": "4dae1d12088fae73ef9b4293a69805a71d8c97197413887e24beb0c3d4edee20"
            },
            "downloads": -1,
            "filename": "flask_rebar-3.3.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a22944adce8fd1643fe64ae25b6f4eca",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 3212447,
            "upload_time": "2024-10-10T17:58:54",
            "upload_time_iso_8601": "2024-10-10T17:58:54.042531Z",
            "url": "https://files.pythonhosted.org/packages/20/d0/ce3623f6026969887ef66acb59612678d55493560258269327b40d430570/flask_rebar-3.3.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb6b0ed6e48d50db99f82b4d03c5e41c19837c074edd9ce08794e1e1aa46266d",
                "md5": "73957d8ad184f29d6da4c7c801df64c7",
                "sha256": "d5f4fe890d7b91780fbae52c62c2cf6a9f2869cf1d23fbf32a8335393c980cab"
            },
            "downloads": -1,
            "filename": "flask_rebar-3.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "73957d8ad184f29d6da4c7c801df64c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3178409,
            "upload_time": "2024-10-10T17:58:56",
            "upload_time_iso_8601": "2024-10-10T17:58:56.427679Z",
            "url": "https://files.pythonhosted.org/packages/fb/6b/0ed6e48d50db99f82b4d03c5e41c19837c074edd9ce08794e1e1aa46266d/flask_rebar-3.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 17:58:56",
    "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.33354s