flask-marshmallow-openapi


Nameflask-marshmallow-openapi JSON
Version 0.6.8 PyPI version JSON
download
home_pageNone
SummaryFlask + marshmallow + OpenAPI
upload_time2025-01-05 10:18:05
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords openapi swaggerui redoc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Overview

[![PyPI Status](https://badge.fury.io/py/flask-marshmallow-openapi.svg)](https://badge.fury.io/py/flask-marshmallow-openapi)
[![license](https://img.shields.io/pypi/l/flask-marshmallow-openapi.svg)](https://opensource.org/licenses/MIT)
[![python_versions](https://img.shields.io/pypi/pyversions/flask-marshmallow-openapi.svg)](https://pypi.org/project/flask-marshmallow-openapi/)
[![documentation](https://readthedocs.org/projects/flask-marshmallow-openapi/badge/?version=latest)](https://flask-marshmallow-openapi.readthedocs.io/en/latest/?badge=latest)


Provides OpenAPI documentation generated from code for
[Flask](https://flask.palletsprojects.com/en/latest/) APIs built around
[marshmallow](https://marshmallow.readthedocs.io/en/stable/) schemas.

This hackish and organically grown ™ package was created because no other similar
projects worked exactly the way I wanted them.

Similar projects:

- [flasgger](https://github.com/flasgger/flasgger)
- [flask-openapi3](https://github.com/luolingchun/flask-openapi3)

## Installation

~~~sh
pip install flask-marshmallow-openapi
~~~

## Documentation

[Read the Docs](https://flask-marshmallow-openapi.readthedocs.io/en/latest)

## What does it do?

Searches your codebase for [marshmallow](https://marshmallow.readthedocs.io/en/stable/)
schemas and 🎖️ decorated 🎖️ Flask routes.

It then produces `swagger.json` and injects it into self-hosted
[ReDoc](https://github.com/Redocly/redoc) and
[SwaggerUI](https://github.com/swagger-api/swagger-ui) documentation viewers.

```py
api = flask.Blueprint("my_api", __name__)


class BookSchema(ma.Schema):
    id = ma.fields.Integer(as_string=True)
    title = ma.fields.String(allow_none=False)
    publisher = ma.fields.String(allow_none=False)
    isbn = ma.fields.String(allow_none=False)


@open_api.get_list(BookSchema)
@api.route("/books", methods=["GET"])
def books_list():
    return "<p>Hello, World!</p>"


app = flask.Flask(__name__)
app.register_blueprint(api, url_prefix="/v1")


conf = OpenAPISettings(
    api_version="v1", api_name="My API", app_package_name="my_api", mounted_at="/v1"
)
docs = OpenAPI(config=conf)
docs.init_app(app)
```

New app routes:

```sh
$ flask routes

Endpoint               Methods  Rule
---------------------  -------  -------------------------------
# ...
open_api.re_doc        GET      /v1/docs/re_doc
open_api.static        GET      /v1/docs/static/<path:filename>
open_api.swagger_json  GET      /v1/docs/static/swagger.json
open_api.swagger_ui    GET      /v1/docs/swagger_ui
open_api.swagger_yaml  GET      /v1/docs/static/swagger.yaml
# ...
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-marshmallow-openapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "OpenAPI SwaggerUI ReDoc",
    "author": null,
    "author_email": "Tomislav Adamic <tomislav.adamic@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/64/9a/3c0e61ba3ac17f05fdb3fdfd4a6a2ce897b37816f2ca405f516332365f0e/flask_marshmallow_openapi-0.6.8.tar.gz",
    "platform": "any",
    "description": "# Overview\n\n[![PyPI Status](https://badge.fury.io/py/flask-marshmallow-openapi.svg)](https://badge.fury.io/py/flask-marshmallow-openapi)\n[![license](https://img.shields.io/pypi/l/flask-marshmallow-openapi.svg)](https://opensource.org/licenses/MIT)\n[![python_versions](https://img.shields.io/pypi/pyversions/flask-marshmallow-openapi.svg)](https://pypi.org/project/flask-marshmallow-openapi/)\n[![documentation](https://readthedocs.org/projects/flask-marshmallow-openapi/badge/?version=latest)](https://flask-marshmallow-openapi.readthedocs.io/en/latest/?badge=latest)\n\n\nProvides OpenAPI documentation generated from code for\n[Flask](https://flask.palletsprojects.com/en/latest/) APIs built around\n[marshmallow](https://marshmallow.readthedocs.io/en/stable/) schemas.\n\nThis hackish and organically grown \u2122 package was created because no other similar\nprojects worked exactly the way I wanted them.\n\nSimilar projects:\n\n- [flasgger](https://github.com/flasgger/flasgger)\n- [flask-openapi3](https://github.com/luolingchun/flask-openapi3)\n\n## Installation\n\n~~~sh\npip install flask-marshmallow-openapi\n~~~\n\n## Documentation\n\n[Read the Docs](https://flask-marshmallow-openapi.readthedocs.io/en/latest)\n\n## What does it do?\n\nSearches your codebase for [marshmallow](https://marshmallow.readthedocs.io/en/stable/)\nschemas and \ud83c\udf96\ufe0f decorated \ud83c\udf96\ufe0f Flask routes.\n\nIt then produces `swagger.json` and injects it into self-hosted\n[ReDoc](https://github.com/Redocly/redoc) and\n[SwaggerUI](https://github.com/swagger-api/swagger-ui) documentation viewers.\n\n```py\napi = flask.Blueprint(\"my_api\", __name__)\n\n\nclass BookSchema(ma.Schema):\n    id = ma.fields.Integer(as_string=True)\n    title = ma.fields.String(allow_none=False)\n    publisher = ma.fields.String(allow_none=False)\n    isbn = ma.fields.String(allow_none=False)\n\n\n@open_api.get_list(BookSchema)\n@api.route(\"/books\", methods=[\"GET\"])\ndef books_list():\n    return \"<p>Hello, World!</p>\"\n\n\napp = flask.Flask(__name__)\napp.register_blueprint(api, url_prefix=\"/v1\")\n\n\nconf = OpenAPISettings(\n    api_version=\"v1\", api_name=\"My API\", app_package_name=\"my_api\", mounted_at=\"/v1\"\n)\ndocs = OpenAPI(config=conf)\ndocs.init_app(app)\n```\n\nNew app routes:\n\n```sh\n$ flask routes\n\nEndpoint               Methods  Rule\n---------------------  -------  -------------------------------\n# ...\nopen_api.re_doc        GET      /v1/docs/re_doc\nopen_api.static        GET      /v1/docs/static/<path:filename>\nopen_api.swagger_json  GET      /v1/docs/static/swagger.json\nopen_api.swagger_ui    GET      /v1/docs/swagger_ui\nopen_api.swagger_yaml  GET      /v1/docs/static/swagger.yaml\n# ...\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Flask + marshmallow + OpenAPI",
    "version": "0.6.8",
    "project_urls": {
        "Source": "https://github.com/tadams42/flask-marshmallow-openapi"
    },
    "split_keywords": [
        "openapi",
        "swaggerui",
        "redoc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "463c2b36d3a9e921f31d9a313f38d6727dace31ca7f40856967d076c7661b0a2",
                "md5": "9bcadbe9101421c7b9273096a7742063",
                "sha256": "6aaf22b4a3211ef8715bcbd0db270f127a62ade9569774670a7e0959d9271781"
            },
            "downloads": -1,
            "filename": "flask_marshmallow_openapi-0.6.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9bcadbe9101421c7b9273096a7742063",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 991991,
            "upload_time": "2025-01-05T10:18:02",
            "upload_time_iso_8601": "2025-01-05T10:18:02.743351Z",
            "url": "https://files.pythonhosted.org/packages/46/3c/2b36d3a9e921f31d9a313f38d6727dace31ca7f40856967d076c7661b0a2/flask_marshmallow_openapi-0.6.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "649a3c0e61ba3ac17f05fdb3fdfd4a6a2ce897b37816f2ca405f516332365f0e",
                "md5": "d3ef53763a34783893e7f9d79e93a5b4",
                "sha256": "e71249da19a91a7b76b0f3d148f7ff26149c5bfb10fdc6b54dce8e50dcd5f2db"
            },
            "downloads": -1,
            "filename": "flask_marshmallow_openapi-0.6.8.tar.gz",
            "has_sig": false,
            "md5_digest": "d3ef53763a34783893e7f9d79e93a5b4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 983020,
            "upload_time": "2025-01-05T10:18:05",
            "upload_time_iso_8601": "2025-01-05T10:18:05.667641Z",
            "url": "https://files.pythonhosted.org/packages/64/9a/3c0e61ba3ac17f05fdb3fdfd4a6a2ce897b37816f2ca405f516332365f0e/flask_marshmallow_openapi-0.6.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-05 10:18:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tadams42",
    "github_project": "flask-marshmallow-openapi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flask-marshmallow-openapi"
}
        
Elapsed time: 0.70108s