Flask + marshmallow + OpenAPI
Project description
Overview
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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flask_marshmallow_openapi-0.6.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a55250cd6b5a05cfca87de89885ceb525bafa8cb0e245e24463ec1bec087ac5 |
|
MD5 | 373d07f3a19e7bf20696c0b1d7049d03 |
|
BLAKE2b-256 | ec172d901ca88ee5924ba35c71c6bb4f8b3f0171f599e1c766bd54b41111910c |
Close
Hashes for flask_marshmallow_openapi-0.6.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 097325f288fec345feb57603e2a4e3121d44be54edf33d5b39a0e4d3b4495b35 |
|
MD5 | 498ffb531ab97ed1562a20e6f9d1a5fa |
|
BLAKE2b-256 | 1b965ab4ea097bb46b83682a220c86322f1c96244eb4368585dd852928d25a2a |