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
File details
Details for the file flask-marshmallow-openapi-0.6.1.tar.gz
.
File metadata
- Download URL: flask-marshmallow-openapi-0.6.1.tar.gz
- Upload date:
- Size: 982.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3522410af64c5036cdb5cb7a55a0eba692f09598452a21ee6a928317202946c2 |
|
MD5 | f031a4fd7303d4daf3c4c257861c0a83 |
|
BLAKE2b-256 | 45fe00b62c894a4c62e33feb636de05dcc3c379a0085e86e391be53880d1bbd1 |
File details
Details for the file flask_marshmallow_openapi-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: flask_marshmallow_openapi-0.6.1-py3-none-any.whl
- Upload date:
- Size: 991.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2e4d46ed488b7c61ac312126bf1bb2cf3fd4140a02b0806ec1b47c8b60772fa |
|
MD5 | dcfba27455111378708e1eab9dc67acd |
|
BLAKE2b-256 | dbb608ff23c9060b7e6a5127386c7fb8ff10a63bec8f799d43cc9b824898dd36 |