Skip to main content

Flask + marshmallow + OpenAPI

Project description

Overview

PyPI Status license python_versions documentation

Provides OpenAPI documentation generated from code for Flask APIs built around marshmallow schemas.

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

Similar projects:

Installation

pip install flask-marshmallow-openapi

Documentation

Read the Docs

What does it do?

Searches your codebase for marshmallow schemas and 🎖️ decorated 🎖️ Flask routes.

It then produces swagger.json and injects it into self-hosted ReDoc and SwaggerUI documentation viewers.

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:

$ 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
# ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_marshmallow_openapi-0.6.7.tar.gz (983.0 kB view details)

Uploaded Source

Built Distribution

flask_marshmallow_openapi-0.6.7-py3-none-any.whl (992.0 kB view details)

Uploaded Python 3

File details

Details for the file flask_marshmallow_openapi-0.6.7.tar.gz.

File metadata

File hashes

Hashes for flask_marshmallow_openapi-0.6.7.tar.gz
Algorithm Hash digest
SHA256 22c3959bf781292e7adeb1cd48e2d484f1c9459c39c7054fd63910feb5d9565c
MD5 4a32f0dcd9cee1fa38e72bebac2d53ab
BLAKE2b-256 5b4a00ce04399b4c4440e8ff776afca6b27d01b32a312a98c80cda0e806e3af6

See more details on using hashes here.

File details

Details for the file flask_marshmallow_openapi-0.6.7-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_marshmallow_openapi-0.6.7-py3-none-any.whl
Algorithm Hash digest
SHA256 643f57c467d31c4ce4b2a0832ad40a26683d0f64aff5fceea4ffc20d84fa1edb
MD5 0d7e29ae481de1db6fe800be596417af
BLAKE2b-256 ef6e60b4de121af714396c473bb5100545589c9c73e6918aa7e40f15e6824235

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page